Programming/Python
connect to DB in python
알 수 없는 사용자
2008. 1. 3. 23:28
import MySQLdb
# Create a connection object and create a cursor
Con = MySQLdb.Connect ( host = "kle.postech.ac.kr", user="joe", passwd = "secrete", db = "onto_web" )
Cursor = Con.cursor ()
#Make SQL string and execute it
sql = "show tables"
Cursor.execute ( sql )
#Fetch all results from the cursor into a sequence and close the connection
Results = Cursor.fetchall ()
Con.close ()
# Create a connection object and create a cursor
Con = MySQLdb.Connect ( host = "kle.postech.ac.kr", user="joe", passwd = "secrete", db = "onto_web" )
Cursor = Con.cursor ()
#Make SQL string and execute it
sql = "show tables"
Cursor.execute ( sql )
#Fetch all results from the cursor into a sequence and close the connection
Results = Cursor.fetchall ()
Con.close ()