gpt4 book ai didi

python - PyMySQL 插入不起作用

转载 作者:行者123 更新时间:2023-11-29 11:07:56 27 4
gpt4 key购买 nike

conn = pymysql.connect(host = '127.0.0.1', unix_socket = '/var/run/mysqld/mysqld.sock',
user = 'root', passwd='', db = 'mysql')

cur = conn.cursor()
cur.execute("USE info")

def store(name, review_url, city, state, zip, phone_number, rooms, email):

# prints this
print('trying to commit')

sql = "INSERT INTO 'Hotels' ('name', 'review_url', 'city', 'state', 'zip', 'phone_number', 'rooms', 'email') VALUES" \
"(%s, %s, %s, %s, %s, %s, %s, %s)"
cur.execute(sql, (name, review_url, city, state, zip, phone_number, rooms, email))
cur.connection.commit()

# doesnt print this
print('tried to commit')

我没有收到任何错误,数据库名称和表名称以及所有列名称都是正确的。

它打印出“尝试提交”,但没有打印出“尝试提交”

有谁知道为什么会这样吗?

最佳答案

你有单引号

"INSERT INTO 'Hotels' ('name', 'review_url', 'city', 'state', 'zip', 'phone_number', 'rooms', 'email') 

尝试不使用单引号或使用反引号

"INSERT INTO Hotels (name, review_url, city, state, zip, phone_number, rooms, email)

关于python - PyMySQL 插入不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41089332/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com