**************************************************
Python Core PlayList : • Lesson - 01 : Python3 - What is python
Python Advanced PlayList : • Lesson - 46 : Python Advanced - Pytho...
**************************************************
Python Database Access : Connecting to Postgresql Databases:
Connect to the Postgres Database using authentication. Catch and print a connection error if one occurs.
#!/usr/bin/python
import psycopg2
import sys
def main():
#Define our connection string
conn_string = "host='localhost' dbname='my_database' user='postgres' password='secret'"
print the connection string we will use to connect
print "Connecting to database\n ->%s" % (conn_string)
get a connection, if a connect cannot be made an exception will be raised here
conn = psycopg2.connect(conn_string)
conn.cursor will return a cursor object, you can use this cursor to perform queries
cursor = conn.cursor()
print "Connected!\n"
if _name_ == "__main__":
main()
Sample Projects : https://github.com/SadaLearningHub1/P...
On this page of the site you can watch the video online Lesson - 60 : Python Advanced - Python Database Access : Connecting to Postgresql Databases with a duration of hours minute second in good quality, which was uploaded by the user Sada Learning Hub 17 January 2018, share the link with friends and acquaintances, this video has already been watched 348 times on youtube and it was liked by 2 viewers. Enjoy your viewing!