Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python SQL排序在字符串格式中不起作用_Python_Sql_Sql Order By - Fatal编程技术网

Python SQL排序在字符串格式中不起作用

Python SQL排序在字符串格式中不起作用,python,sql,sql-order-by,Python,Sql,Sql Order By,我有一个sql,它可以工作: cursor.execute('select * from video_title_difference where title like %s order by provider desc limit %s offset %s', ('%' + search + '%', limit, offset)) 但是如果我将ORDER BY变量(即现在的“提供者”)更改为变量,则它根本不起作用: cur

我有一个sql,它可以工作:

cursor.execute('select * from video_title_difference where title like 
                %s order by provider desc limit %s offset %s', 
                ('%' + search + '%', limit, offset))
但是如果我将ORDER BY变量(即现在的“提供者”)更改为变量,则它根本不起作用:

cursor.execute('select * from video_title_difference where title like %s 
                order by %s limit %s offset %s', 
               ('%' + search + '%', order_by, limit, offset))

它“有效”,但它根本不订购。我做错了什么?

问题是您试图将表设置为参数

表名不能参数化

我的方法是在代码中硬编码表名,您需要了解使用表名可能会导致安全问题,特别是当它来自用户时

我将添加一些关于此问题的帖子:

,,