我有以下用于查询的python代码:
import mysql.connector
from mysql.connector import errorcode
config = {
'user': 'root',
'password': 'root',
'host': 'localhost',
'database': 'myDatabase'}
cn = mysql.connector.connect(**config)
cur = cn.cursor()
emailExist = cur.execute("""SELECT * FROM
customerDetails""").fetchall()
print(emailExist)
并获取以下错误:
emailExist = cur.execute("""SELECT * FROM customerDetails""").fetchall()
AttributeError: 'NoneType' object has no attribute 'fetchall'
我的数据库文件与此脚本位于同一目录中
在MySQLWorkbench中运行相同查询时,输出为:
返回0行
添加了插入代码:
cursor = cn.cursor()
sql1 = """INSERT INTO customerDetails
VALUES (3, "h", "h",
"h", "h", "h",
"h", "h", "h",
1, 1, 1)"""
result = cursor.execute(sql1)
cursor.close()
cn.close()
文件:https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-fetchall.html
这意味着:
cur.execute("""SELECT * FROM customerDetails""")
返回None,并且它没有fetchall
属性必须对游标(
cur.fetchall()
)使用fetchall()方法相关问题 更多 >
编程相关推荐