Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
返回Python SQL查询“非类型”对象_Python_Mysql_Sql_Python 3.x - Fatal编程技术网

返回Python SQL查询“非类型”对象

返回Python SQL查询“非类型”对象,python,mysql,sql,python-3.x,Python,Mysql,Sql,Python 3.x,我有以下用于查询的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()

我有以下用于查询的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.executeSELECT*自customerDetails.fetchall

AttributeError:“非类型”对象没有属性“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()
文件:

AttributeError:“非类型”对象没有属性“fetchall”

这意味着:

cur.executeSELECT*FROM customerDetails返回None,并且没有fetchall属性

您必须在光标cur上使用fetchall方法。fetchall。

execute不会返回任何内容。对游标对象本身调用fetchall!