Python pymySQL 字符串引号
Python pymySQL string quotes
我正在尝试插入一个字符串
insert_cmd = "INSERT INTO inv values (\""+str(row[1])+"\",\""+str(row[2])+"\")
(cur.execute(insert_cmd))
错误信息:
pymysql.err.ProgrammingError: (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'google search appliance"","active","D\' at line 1')
最好使用查询参数来避免引用和其他问题:
cur.execute("INSERT INTO inv values (%s, %s)", (str(row[1]), str(row[2])))
最好为列命名,以防以后模型发生变化:
"INSERT INTO inv (col1, col2) VALUES (%s, %s)"
我正在尝试插入一个字符串
insert_cmd = "INSERT INTO inv values (\""+str(row[1])+"\",\""+str(row[2])+"\")
(cur.execute(insert_cmd))
错误信息:
pymysql.err.ProgrammingError: (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'google search appliance"","active","D\' at line 1')
最好使用查询参数来避免引用和其他问题:
cur.execute("INSERT INTO inv values (%s, %s)", (str(row[1]), str(row[2])))
最好为列命名,以防以后模型发生变化:
"INSERT INTO inv (col1, col2) VALUES (%s, %s)"