Python + MySQL (Win32)
Ingo Linkweiler
i.linkweiler at web.de
Wed Dec 4 07:58:16 EST 2002
# Perhaps this helps?
# A simple mysql-test
# requires a database test, table benutzer, rows (userid, name)
import MySQLdb
db=MySQLdb.connect("localhost","user","pass","test")
c=db.cursor(MySQLdb.cursors.DictCursor)
# insert new item
# c.execute("""INSERT INTO benutzer (userid, name) VALUES (7,"Thomas")""")
c.execute("""REPLACE INTO benutzer (userid, name) VALUES (7,"Thomas3")""")
# start...
print c.execute("""SELECT * FROM benutzer""")
# get one item
print c.fetchone()
# get all items
print c.fetchall()
print "finished"
# Testen der Datenbank
import _mysql
try:
db=_mysql.connect("localhost","inli","1","test2")
except:
print "Fehler beim verbinden mit der Datebbank."
db.query("CREATE TABLE hoho (name VARCHAR(20), id INT)")
db.close()
More information about the Python-list
mailing list