question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Incorrect arguments to mysqld_stmt_execute when trying to SET with .execute()

See original GitHub issue

Hi everyone, Trying to wrap my head around async here. I’ve extracted my connection code using the following :

const mysql   = require('mysql2/promise');
const config  = require("./config");

/*
 * @sqlConnection
 * Creates the connection, makes the query and close it to avoid concurrency conflicts.
 */
var sqlConnection = async function sqlConnection(sql, values, next) {
    // It means that the values hasnt been passed
    if (arguments.length === 2) {
        next = values;
        values = null;
    }
    const connection = await mysql.createConnection(config.db);
    /*connection.connect(function(err) {
        if (err !== null) {
            console.log("[MYSQL] Error connecting to mysql:" + err+'\n');
        }
    });*/
    const [rows, fields] = await connection.execute(sql, values, function(err) {
      if (err) {
          throw err;
      }
      // Execute the callback
      next.apply(this, arguments);
    });
}
module.exports = sqlConnection;

I’m trying to insert into my database using the following :

var db_results = db_connection('INSERT INTO organisation (name, social, address, country, zip) VALUES (?,?,?,?,?)', {name: input.name, social: input.social, address: input.address, country: input.country, zip: input.zip}, function (error, rows) { console.log(query.sql); });

I’ve tried quite a few things, using SET, changing the number of ?, naming or not the query, yet I keep getting

Error: Incorrect arguments to mysqld_stmt_execute

Any insight ?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sidorarescommented, Apr 2, 2018

re main question: you must use one simple type value per ?:

db_connection('INSERT INTO organisation (name, social, address, country, zip) VALUES (?,?,?,?,?)', [input.name, input.social, input.address, input.country, input.zip], function (error, rows) { 
   console.log(error, rows); 
});
1reaction
sidorarescommented, Apr 2, 2018

I think this is unrelated to main question, but why are you using await and callback together?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Incorrect arguments to mysqld_stmt_execute
const [result] = await mysql.execute( `SELECT * FROM user LIMIT ${pageNumber},20;` );. and, if the variable is a string, put ' ' around...
Read more >
Incorrect arguments to mysqld_stmt_execute (MySQL 8.0.22)
Hi, love this library! ... Now this error is wrapped by my own logic, but the cause I think it quite clear: Incorrect...
Read more >
Error 1210 - “Incorrect arguments to mysqld_stmt_execute
We suspect the query failure happens when we create a row in the table containing a blob column and if the blob is...
Read more >
Python MySQL Execute Parameterized Query using Prepared ...
execute() function to run a parameterized query. SQL query; A tuple of parameter values. In our case, we need to pass two Python...
Read more >
Cloud SQL for MySQL error messages
In this case, the request is using either the wrong argument or an ... The error has also been seen when trying to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found