我想使用游标执行 mysql 查询,但我无法这样做。错误显示:AttributeError: 'NoneType' object has no attribute 'execute'
我的代码中共有 3 个游标(我无法仅使用 1 个游标)并且所有游标都已连接(我通过调试进行了检查)
我已经完成了这个线程,但它不起作用Python:MySQL 连接已打开,但无法创建游标
从 fpdf 导入 FPDF,HTMLMixin 导入 mysql.connector
#from mysql.connector import error
class HTML2PDF(FPDF, HTMLMixin):
pass
conn = mysql.connector.connect(host='localhost',
database='swd',
user='root',
password='param2000')
conn1 = mysql.connector.connect(host='localhost',
database='swd',
user='root',
password='param2000')
conn2 = mysql.connector.connect(host='localhost',
database='swd',
user='root',
password='param2000')
#all 3 are successfully connected
cursor = conn.cursor()
cursor.execute("SELECT * from 14batch")
row=cursor.fetchone()
#cursor works perfectly
html='''blah blah blah'''
cursor1=conn1.connect()
cursor1.execute("SELECT * from med_ins_14batch where uid='row[0]'")
#it throws me an error in the above line
row1 = cursor1.fetchone()
AttributeError: 'NoneType' 对象没有属性 'execute'
查看代码中的差异。
首先,cursor
是使用游标创建的。其次,cursor1
不是以同样的方式被创造。
将失败的一组行更改为:
html='''blah blah blah'''
cursor1=conn1.cursor()
cursor1.execute("SELECT * from med_ins_14batch where uid='row[0]'")
#this should work now
row1 = cursor1.fetchone()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句