代码之家  ›  专栏  ›  技术社区  ›  Eden Reich

NODEJS MySQL绑定抛出ER_PARSE_错误1064

  •  0
  • Eden Reich  · 技术社区  · 7 年前

    考虑到以下因素:

    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 回复  |  直到 7 年前
        1
  •  2
  •   danblack    7 年前

    只能绑定值。列名(in ORDER BY ),以及 :direction

    推荐文章