Reading from a Database : MySQL : Database PYTHON examples


PYTHON examples » Database » MySQL »

 

Reading from a Database





import MySQLdb

db= MySQLdb.connect(host="localhost", user="python-test", passwd="python",
db="python-test")

cursor = db.cursor()
stmt = "SELECT * from books"
cursor.execute(stmt)

rows = cursor.fetchall ()
for row in rows:
    print "Row: "
    for col in row :
        print "Column: %s" (col)
    print "End of Row"
print "Number of rows returned: %d" % cursor.rowcount

cursor.close()

db.close()

 



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON examples

 Navioo Database
» MySQL