problems with making sql queries in nodejs

3

The id is passed by parameter to my query function, but it fails to execute the query

this is my code:

objBD.query('SELECT u.ID_U, u.nombre, l.ID_L,letra, t.ID_T,tiempo from USUARIO u INNER JOIN LETRA l ON u.ID_U = l.ID_U INNER JOIN TIEMPOS t ON l.ID_L=t.ID_L where u.ID_U='+result.insertId', function(err, rows, fields) {
        console.log(rows);

result.insertId is the id, my question is how to make a query with a parameter?

    
asked by hubman 05.10.2016 в 18:39
source

1 answer

0

I solved it like this:

objBD.query('SELECT u.ID_U, u.nombre, l.ID_L,letra, t.ID_T,tiempo from USUARIO u INNER JOIN LETRA l ON u.ID_U = l.ID_U INNER JOIN TIEMPOS t ON l.ID_L=t.ID_L where u.ID_U=?',[result.insertId], function(err, rows, fields) {
        console.log(rows);
        //

});

Putting in brackets the required parameters, they are separated by commas each parameter required to perform the query.

    
answered by 05.10.2016 / 19:52
source