'mysql + python'에 해당되는 글 1

  1. 2008.01.03 connect to DB in python
Programming/Python | Posted by 알 수 없는 사용자 2008. 1. 3. 23:28

connect to DB in python

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 ()