Skip to content
Advertisement

How to correctly execute this promise based SQL Query?

I’m using MySQL2 to connect my Node.js app with a MySQL Database. Unfortunately trying to perform some promise based prepared statements I just can’t get a proper function setup that either returns successfully after entering the record or to throw an error whenever something goes wrong.

Any ideas on how to fix the code below?

Advertisement

Answer

you can use the prepared statement query function like below.

If you are not using this inside a function

Or use async await

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement