How to pass arguments on a stored procedure in Mysql?

Asked

Viewed 15 times

0

How do I pass these arguments inside CALL? When I put 9 random values inside LET sql("..."), it runs, but passing this way returns this error. I followed this tutorial -> https://www.mysqltutorial.org/mysql-nodejs/call-stored-procedures/ But it does not teach how to pass more than one argument, if anyone can help me I thank. (Note: I am beginner)

Code:

router.post('/pedido_final', function(req, res){

  let connection = mysql.createConnection({
    host: 'localhost',
    port: 3309,
    user: 'root',
    password: 'XXXXX',
    database: 'XXXXX'
  });

  let sql = `CALL recebePedido(?)`

  let dados = [req.body[0].nMesa, req.body[0].idProd, req.body[0].Quantidade,
  req.body[0].codFun, req.body[0].p, req.body[0].sabores, req.body[0].nomeCli, req.body[0].nmrCelCli, 
  req.body[0].Obs]

  connection.query(sql, dados, (error, results, fields) => {
    if (error) {
      return console.error(error.message);
    }
    console.log(results[0]);
  });
  
  connection.end(); });

I get the following error this way: inserir a descrição da imagem aqui

1 answer

0


Try changing that line:

Let sql = CALL recebePedido(?) for sql Let = CALL recebePedido(?,?,?,?,?,?,?,?,?) because he is complaining that he expects nine arguments and Voce is passing only 1.

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.