Python MySQLdb Library
return to DevPythonConnect
import MySQLdb # set or replace constants db = MySQLdb.connect(host=DB_HOST, user=DB_USER, passwd=DB_PASS, db=DB_NAME)
Select Query
import MySQLdb
db = MySQLdb.connect(host=DB_HOST, user=DB_USER, passwd=DB_PASS, db=DB_NAME)
c = db.cursor()
c.execute("""SELECT * FROM table WHERE condition = 1""")
rows = c.fetchall()
print type(rows), rows
c.close()
db.close()
[There are no comments on this page]