haixin3036 发表于 2018-8-11 13:36:50

Python学习之MySQLdb模块

import MySQLdb  

  
db=MySQLdb.connect(host='127.0.0.1',user='jialebi',passwd='jialebi123',db='dream_android_game_center')
  
cur=db.cursor()
  
try:
  
   cur.execute("SELECT * FROM account")
  
   rows=cur.fetchall()
  
except MySQLdb.Error,e:
  
   try:
  
       print "MySQL Error [%d] : %s" % (e.args,e.args)
  
   except IndexError:
  
       print "MySQL Error: %s" % str(e)
  
for row in rows:
  
    for col in row:
  
      print "%s," %col
  
    print "\n"
页: [1]
查看完整版本: Python学习之MySQLdb模块