'ER_PARSE_ERROR' You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version

Viewed 41

I created in my model the const getbypage:

   const getByPage = (page = 1, limit = 10) => {
       return executeQuery(
           'select * from clientes limit ? offset = ?',
           [limit, (page-1) * limit]
       );
   }

in the controller:

router.get('/', async (req, res) => {
    try {
        const clients = await getByPage();
        res.render('clients/list', { arrClients: clients });
    } catch (err) {
        console.log(err);
    }
});

and the error is:

code: 'ER_PARSE_ERROR', errno: 1064, sqlState: '42000', sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= 0' at line 1", sql: 'select * from clientes limit 10 offset = 0' } GET /clients - - ms - -

CAN SOMEBODY HELP ME?

1 Answers

https://dev.mysql.com/doc/refman/8.0/en/select.html shows you the reference documentation for the LIMIT clause:

[LIMIT {[offset,] row_count | row_count OFFSET offset}]

There's no = in the syntax. You should just use OFFSET ?.

WRONG:

select * from clientes limit ? offset = ?

RIGHT:

select * from clientes limit ? offset ?
Related