使用python-mysql执行mysql查询?

2024-09-29 02:18:34 发布

您现在位置:Python中文网/ 问答频道 /正文

考虑下面的代码

Table="USER"
fields="("+'username'+")"
values=('vishnu',)
dbcon = MySQLdb.connect(...)
insert_query="insert into %s%s values%%s"%(Table,fields)

cursor=dbcon.cursor()
cursor.execute(insert_query,(values,))
cursor.close()
dbcon.commit()

对于两个系统,此代码的工作方式不同。在我的笔记本电脑,它工作得很好,但在我的桌面上,它显示MYSQL语法错误。你知道吗

我不能解决这个问题?原因是什么,我使用的是相同版本的python2.7。你知道吗


Tags: 代码fieldsexecuteconnecttableusernamequerycursor