我想用准备好的语句从表中删除一行,但结果是错误的。mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement
相关代码:
db = mysql.connector.connect(
host='localhost',
user='user',
database='web_board',
password='password',
auth_plugin='mysql_native_password'
)
crs = db.cursor()
# construct the query and remove post from the database
query = 'DELETE FROM posts WHERE postid=%s'
crs.execute(query, tuple(request.data))
db.commit()
crs.close()
db.close()
request.data
看起来是这样的 b'9b23f24e-ff4d-4113-85ae-ff8a4a5de3be'
由于 文件规定为了使用准备好的语句,你应该用下面的配置实例化你的游标。
crs = db.cursor(prepared=True)
使用MySQLCursorPrepared执行的预处理语句可以使用格式(%s)或qmark(?)参数化风格。