2

I'd like to know what could I use as alternative for PHP PDO in Node.js

I've found node-mysql2, they talk about prepared statements but I can't find a way to cache the statement to reuse it.

With PHP I do:

$sth = $pdo->prepare('SELECT 1+? AS test1');
$sth->execute( Array(10) );
$sth->execute( Array(20) );

And with this I don't prepare the query each time, I juse use the prepared one changing the variable value.

With node-mysql2 instead I do:

connection.execute('SELECT 1+? AS test1', [10], function(err, rows) {
  //
});

But I can't find a way to take advantages by the prepared statement feature.

1 Answer 1

4

Referencing this thread near the end you can see this answer to your question:

Sorry, I was completely wrong about node-mysql2. It does indeed prepare once. The API led me to believe that it didn't have a separate prepare and execute, but I looked at the code and found that it does have a cache that reuses the prepared statement if you use the same query text.

I was a bit nasty when I posted that comment. I was frustrated. Sorry about that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.