python连接mysql数据库时,python用的2.5,mysqldb用的2.5,mysql用的6.0.2,连接成功,但是得不到cursor对象,即报的错为AttributionError:'Connection' object has no attribute 'cursorclass'
这是我的代码:
try:
conn=MySQLdb.connect(host='localhost',user='root',passwd='111111',db='bookcrossing',port=3306)
cur=conn.cursor()
cur.execute('select * from bx-book-ratings where User-ID=2')
results=cur.fetchall()
for r in results:
print "User-ID:%s ISBN:%s Book-Rating:%s"%r
cur.close()
conn.close()
except:
print "Could not connect to MySQL server."
exit(0)
这是我的代码:
try:
conn=MySQLdb.connect(host='localhost',user='root',passwd='111111',db='bookcrossing',port=3306)
cur=conn.cursor()
cur.execute('select * from bx-book-ratings where User-ID=2')
results=cur.fetchall()
for r in results:
print "User-ID:%s ISBN:%s Book-Rating:%s"%r
cur.close()
conn.close()
except:
print "Could not connect to MySQL server."
exit(0)
这是说 你引用的conn类没有这个属性吧!
是不是引用的lib错误还是版本问题!自己查一下api
mysqldb用的2.5,mysql用的6.0.2
这两个版本可能不匹配。