MySQLdb Python insert %d and %s

馋奶兔 提交于 2019-12-02 22:53:23
noobmaster69

As the whole query needs to be in a string format while execution of query so %s should be used...

After query is executed integer value is retained.

So your line should be.

.execute("INSERT INTO table VALUES(%s,%s)", (int(id), string))

Explanation is here

The format string is not really a normal Python format string. You must always use %s for all fields

You missed a '%' in string formatting

"(INSERT INTO table VALUES(%d,%s)"%(int(id), string))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!