因此,在我的服务器中,我有:
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记录在控制台中。我将限制的第一个参数作为? [pageno]传递,如他们的official notes中所述。如果我在LIMIT 2,3中输入2或任何其他数字,它就可以工作。我在表中有一千多条虚拟记录。
我还尝试了var sql = 'SELECT * FROM mytable LIMIT ' + connection.escape(pageno) + ', 3';,并在connection.query中使用了sql,但出现了相同的错误。
我做错了什么?请帮帮忙。
https://stackoverflow.com/questions/47496572
复制相似问题