无法使用 node-mysql 进行分页

Unable to paginate with node-mysql

所以在我的服务器中我有:

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

我收到错误:

{ 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 已记录在控制台中。我将 LIMIT 的第一个参数作为 ? [pageno] 传递,如他们的 official notes 中所述 如果我在 LIMIT 2,3 中键入 2 或任何其他数字,有用。我在 table 中有超过一千条虚拟记录。

也试过了 var sql = 'SELECT * FROM mytable LIMIT ' + connection.escape(pageno) + ', 3'; 并在 connection.query 中使用 sql 但同样的错误。

我做错了什么?请帮忙。

您可以尝试 parseInt() 页码。