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')
我没有收到任何错误,数据库名称和表名都是正确的以及所有列名。
它打印出“尝试提交”#39;但它没有打印出来,试图提交'
有谁知道为什么会这样?
答案 0 :(得分:1)
你有单引号
"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)