Python + MySQL (Win32)

Kristian Kuula e8Kuula at hotmail.com
Thu Dec 5 05:18:10 EST 2002


"Ingo Linkweiler" <i.linkweiler at web.de> wrote in message
news:3DEDFBE8.2020204 at web.de...
> # 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()

Wow!, it seems to work! :) Thanks!




More information about the Python-list mailing list