前体:
MySQL Table created via: CREATE TABLE table(Id INT PRIMARY KEY NOT NULL, Param1 VARCHAR(50))
功能:
.execute("INSERT INTO table VALUES(%d,%s)", (int(id), string)
输出:
TypeError: %d format: a number is required, not a str
我不确定这里发生了什么,为什么我无法执行命令.这是在Python中使用MySQLdb..execute是在游标对象上执行的.
编辑:
主题:Python MySQLdb问题(TypeError:%d格式:需要一个数字,而不是str) 表示必须对所有字段使用%s.为什么会这样?为什么这个命令有效?
.execute("INSERT INTO table VALUES(%s,%s)", (int(id), string)
noobmaster69.. 24
由于整个查询需要采用字符串格式,因此%s
应该使用查询执行...
执行查询后,将保留整数值.
所以你的路线应该是.
.execute("INSERT INTO table VALUES(%s,%s)", (int(id), string))
解释在这里