我在mysql中创建了程序输入编号和删除数据。但运行程序错误然后报告sql1
语法错误\ i更改为真
#!/usr/bin/python
import mysql.connector
conn = mysql.connector.connect(host="",user="",passwd="",db="")
cursor = conn.cursor()
try:
num = int(input("InputNumber 1-10 : "))
if num <= 10:
if num == null: //if null print false
sql1 = "SELECT user1 FROM dt WHERE user1 = '%d' " %(num)
cursor.execute(sql1)
data = cursor.fetchall()
print(data[0])
sqlde = "DELETE FROM dt WHERE user1 = '%d' " %(num)
cursor.execute(sqlde, (num))
print "DELETE SUCESS"
conn.commit()
else:
print "Data Empty"
except:
conn.rollback()
conn.close()
答案 0 :(得分:2)
num = int(输入(“InputNumber:”)class Candidate::JobsController < Candidate::BaseController
end
&lt; - 不要忘记关闭它
我不确定)
,我总是看到%i
用于整数,%d
用于字符串
但是,您的查询中也存在一个问题,SQL Injection
为避免这种情况,请尝试这样的事情
%s
您可以查看question mark here或here,了解绑定价值的原因