Python 在我的SQL SELECT语句中使用通过瓶子路由传递的参数

Python 在我的SQL SELECT语句中使用通过瓶子路由传递的参数,python,mysql,bottle,Python,Mysql,Bottle,在SQL语句中使用通过瓶路由传递的参数的正确语法是什么?(为了清晰起见,这里省略了大量代码,除此之外,其他一切都正常工作) @route('/sqldynamic/')) def sqlDyanmic(foo,bar): db=MySQLdb.connect(“127.0.0.1”、“用户名”、“密码”、“数据库”) cursor=db.cursor() execute(“选择this,this>foo以及类似于“%bar%”的内容) data=cursor.fetchall() 返回str(数

在SQL语句中使用通过瓶路由传递的参数的正确语法是什么?(为了清晰起见,这里省略了大量代码,除此之外,其他一切都正常工作)

@route('/sqldynamic/'))
def sqlDyanmic(foo,bar):
db=MySQLdb.connect(“127.0.0.1”、“用户名”、“密码”、“数据库”)
cursor=db.cursor()
execute(“选择this,this>foo以及类似于“%bar%”的内容)
data=cursor.fetchall()
返回str(数据)

因为您使用的是MySQL:

cursor.execute("SELECT this, that WHERE this > %s AND that like %s;", (foo, bar))
(这与瓶子无关。)


(另外,如果您关心SQL注入,那么您应该添加一些验证。)

很好,很乐意提供帮助。
cursor.execute("SELECT this, that WHERE this > %s AND that like %s;", (foo, bar))