Python使用MySQL驱动

#!/usr/bin/python
# -*- coding: utf-8 -*-

import MySQLdb

db=MySQLdb.connect(host="127.0.0.1",port=3306,db="django",user="sa",passwd="sa")
cur=db.cursor()
cur.execute("select count(*) from djuser")
print("rowcount=",cur.rowcount)

rows=cur.fetchall()
for row in rows:
    print("%s" % (row[0]))

Leave a Reply

Your email address will not be published. Required fields are marked *

*