检查查询语句是否正确,并使用循环或其他适当的方式来处理多个结果。以下是一个简单的示例:
import mysql.connector
# 连接到数据库
mydb = mysql.connector.connect(
host="localhost",
user="yourusername",
password="yourpassword",
database="mydatabase"
)
# 执行查询
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM customers WHERE address = 'Park Lane 38'")
# 处理结果
result = mycursor.fetchall()
for x in result:
print(x)
在上面的代码中,我们使用循环来处理查询返回的所有结果。如果查询只返回一个结果,我们也可以使用mycursor.fetchone()
来获取该结果。
上一篇:API支持B2B客户登录
下一篇:API只返回没有内容的响应。