Wiki source for PythonMysqldb


Show raw source

=====Python MySQLdb Library=====
return to DevPython

===Connect===
%%
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()
%%

===References===
http://mysql-python.sourceforge.net/MySQLdb.html
Valid XHTML 1.0 TransitionalValid CSSWikkaWiki