Simple csv dump script


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. SELECTQ="SELECT * FROM category"
  2. FILENAME="dump.csv"
  3.  
  4. import MySQLdb
  5. import csv
  6.  
  7. db = MySQLdb.connect(host="localhost", user="root", passwd="", db="sakila")
  8. dump_writer = csv.writer(open(FILENAME,'w'), delimiter=',',quotechar="'")
  9. cursor = db.cursor()
  10. cursor.execute(SELECTQ)
  11. result = cursor.fetchall()
  12. for record in result:
  13. dump_writer.writerow(record)
  14.  
  15. db.close()

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.