首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用node-mysql进行分页

无法使用node-mysql进行分页
EN

Stack Overflow用户
提问于 2017-11-26 21:18:41
回答 0查看 439关注 0票数 0

因此,在我的服务器中,我有:

代码语言:javascript
复制
app.get('/getposts/:pageno', (req, res) => {

  let pageno = req.params.pageno

  connection.query('SELECT * FROM mytable LIMIT ? , 3', [pageno], function(err, rows, fields){
        if(err){
            console.log(err);
        }

        res.send(rows);

        console.log(pageno);
    });

});

当我尝试像这样访问它时:http://localhost:3000/getposts/2

我得到了错误:

代码语言:javascript
复制
{ Error: ER_PARSE_ERROR: 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 ''2' , 3'

 code: 'ER_PARSE_ERROR',
  errno: 1064,
  sqlMessage: '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
\'\'2\' , 3\' at line 1',
  sqlState: '42000',
  index: 0,
  sql: 'SELECT * FROM mytable LIMIT \'2\' , 3' }

pageno记录在控制台中。我将限制的第一个参数作为? [pageno]传递,如他们的official notes中所述。如果我在LIMIT 2,3中输入2或任何其他数字,它就可以工作。我在表中有一千多条虚拟记录。

我还尝试了var sql = 'SELECT * FROM mytable LIMIT ' + connection.escape(pageno) + ', 3';,并在connection.query中使用了sql,但出现了相同的错误。

我做错了什么?请帮帮忙。

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47496572

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档