NODEJS MySQL绑定抛出ER_PARSE_ERROR 1064

时间:2018-09-16 10:59:46

标签: mysql node.js typescript

给出以下内容:

let sql: any = 'SELECT * FROM test_people ORDER BY :column :direction LIMIT :limit, :offset';
let binds: any = { column: 'name', direction: 'desc', limit: '1', offset: '10' };

let result = await mysql.query(sql, binds);

无论出于何种原因,它都会引发mysql语法错误,如果我替换了绑定并在没有绑定的情况下对其进行了硬编码,则查询实际上可以工作并获取结果。不知道这里出了什么问题。救命 ! :)

顺便说一句,我也尝试使用问号版本,但出现相同的语法错误。

错误输出:

 ...
 code: 'ER_PARSE_ERROR',
 errno: 1064,
'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near \':column :direction LIMIT :limit, :offset\' at line 1',
 ...

赞赏任何解决方案,

1 个答案:

答案 0 :(得分:2)

只能绑定值。列名(在ORDER BY中)和:direction无法绑定。 FYI表名,数据库名和SQL语法的其他部分也无法绑定。