运行环境:
python:3.2
mysql:5.6
系统:win7
python代码:
import MySQLdb
con = MySQLdb.connect(host='localhost', user='root', passwd='root', db='hr_resume_center', charset='utf8')
cursor = con.cursor()
sql = "INSERT INTO hr_resume_core (resume_id,name,mobile,email,add_time,sys_time,version) VALUES(%s,%s,%s,%s,%s,%s,%s)"
param = [1,'bright','13641154657','jackieming\@sina.cn',1385625423,1385625423,1]
cursor.execute(sql,param)
cursor.close()
con.close()
报错:
Traceback (most recent call last):
File "E:\python\mysqldb\demo1\demo_insert.py", line 10, in <module>
cursor.execute(sqls,param)
File "D:\Python32\lib\site-packages\MySQLdb\cursors.py", line 184, in execute
self.errorhandler(self, exc, value)
File "D:\Python32\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
raise errorclass(errorvalue)
_mysql_exceptions.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 '%s,%s,%s,%s,%s,%s,%s)' at line 1")
问题
我查过好多资料都显示可以使用%s的占位符方式执行sql,为什么我使用这种方式总是报错?通过错误提示看好像是sql语句的问题,希望有人能指导一下。
param should be a tuple, other than a list.