/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
SELECTQ="SELECT * FROM category" FILENAME="dump.csv" import MySQLdb import csv db = MySQLdb.connect(host="localhost", user="root", passwd="", db="sakila") dump_writer = csv.writer(open(FILENAME,'w'), delimiter=',',quotechar="'") cursor = db.cursor() cursor.execute(SELECTQ) result = cursor.fetchall() for record in result: dump_writer.writerow(record) db.close()