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

Опубликовано: 17 Январь 2018
на канале: 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...


На этой странице сайта вы можете посмотреть видео онлайн Lesson - 60 : Python Advanced - Python Database Access : Connecting to Postgresql Databases длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Sada Learning Hub 17 Январь 2018, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 348 раз и оно понравилось 2 зрителям. Приятного просмотра!