1

I use the following code using mysql with Node.js

var mysql = require('mysql');
var db = mysql.createConnection({host:'localhost', user:'root', password: 'pw', database: 'db'});
db.connect();

And, I use this to SELECT data and handle error.

db.query("SELECT * FROM user_info WHERE uid = ? LIMIT 1", [selfid], function(err, rows, fields) {
    if (err) throw err;
    // do something....
});

But, I want to ask that when I use "INSERT" and some error happens, will the app.js crash if I haven't handle error?

var qstr = "INSERT INTO user_info (uid, message, created_time) VALUES(?, ?, CURRENT_TIMESTAMP)";
db.query(qstr, [uid, message]);

1 Answer 1

1

No, the app will not crash if you do not handle your errors. It will continue silently. It is up to you to catch the errors and handle them.

var qstr = "INSERT INTO user_info syntax error";
db.query(qstr, function(err) {
    if (err) {
        console.log("A wild error appeared!", err);
        process.exit(1);
    }
});
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.