rendered paste bodyimport sys
import MySQLdb
conn = MySQLdb.connect (host = "localhost", user = "testuser", passwd = "testpass", db = "test")
cursor = conn.cursor ()
cursor.execute ("DROP TABLE IF EXISTS test")
cursor.execute ("""
CREATE TABLE test
(
name CHAR(40),
category CHAR(40)
)
""")
cursor.execute ("""
INSERT INTO test (name, category)
VALUES
('snake', 'reptile'),
('frog', 'amphibian'),
('tuna', 'fish'),
('racoon', 'mammal')
""")
print "Number of rows inserted: %d" % cursor.rowcount
cursor.execute ("SELECT name, category FROM test")
while (1):
row = cursor.fetchone ()
if row == None:
break
print "%s, %s" % (row[0], row[1])
print "Number of rows returned: %d" % cursor.rowcount
cursor.close ()
conn.commit ()
conn.close ()