Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

827
Visualizações
Error: Incorrect arguments to mysqld_stmt_execute

I am working on a nodeJs project and using a npm package mysql2 for mysql database.

My MySql Configuration:-

let mysql = MYSQL.createConnection({
  host: `${config.mysql.host}`,
  user: `${config.mysql.user}`,
  password: `${config.mysql.password}`,
  database: `${config.mysql.db}`,
});

When I am using a query

async function getUsers ({pageNumber}) { // suppose pageNumber = 1
  const [result] = await mysql.execute(
   `SELECT * FROM user LIMIT ?,20;`,
    [pageNumber]
  );
  return result;
}

The above code is working fine. But when i am trying to multiply any number with pageNumber,it throws error Error: Incorrect arguments to mysqld_stmt_execute

Ex.

async function getUsers ({pageNumber}) { // suppose pageNumber = 1
  pageNumber = pageNumber * 20; // here we multiply 20 with pageNumber (20 is the row limit)
  const [result] = await mysql.execute(
   `SELECT * FROM user LIMIT ?,20;`,
    [pageNumber]
  );
  return result;
}

above code throws the error.

Note:- type of pageNumber is number not string.

Please help.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

This appears to be a bug introduced in MySQL version 8.0.22, I'm getting the same error after updating from 8.0.19. Not sure about the cause or a proper solution, in the interim I'm mapping the values to strings, as per https://github.com/sidorares/node-mysql2/issues/1239#issuecomment-718471799, which seems to work.

over 4 years ago · Santiago Trujillo Relatório

0

is like a buggy, use interpolation like this(yes is a bad practice, but you can make a solution meanwhile) :

const [result] = await mysql.execute(
   `SELECT * 
    FROM user 
    LIMIT ${pageNumber},20;` 
  );

and, if the variable is a string, put ' ' around the interpolation

`SELECT * FROM user WHERE xname = '${x}'  ;`
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda