Lesson - 60 : Python Advanced - Python Database Access : Connecting to Postgresql Databases

Veröffentlicht am: 17 Januar 2018
auf dem Kanal: Sada Learning Hub
348
2

**************************************************
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...


Auf dieser Seite können Sie das Online-Video Lesson - 60 : Python Advanced - Python Database Access : Connecting to Postgresql Databases mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Sada Learning Hub 17 Januar 2018 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 348 Mal angesehen und es wurde von 2 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!