亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - Mysql query exception occurs in node.js, how to deal with it?
某草草
某草草 2017-05-16 13:35:53
0
2
923

Based on the express framework, node-mysql module development project needs to execute sql statements in the project. If the sql statement is abnormal, the program will crash directly.

conn.query(sql,function (err, result) {}
如果這里的事情了因?yàn)榍岸颂峤环绞降脑颍ɑ蛘呤莿e人的非法提交),sql語(yǔ)句變?yōu)榱?SELECT * FROM prod WHERE prodName LIKE'%undefined%' LIMIT NaN,10; 
這樣的話(huà),node控制臺(tái)會(huì)拋出:throw err; // Rethrow non-MySQL errors
node就崩潰了,請(qǐng)問(wèn)有什么好的方式處理sql異常?
某草草
某草草

reply all(2)
我想大聲告訴你

Process your sql and set illegal values ??as default values

某草草

Try adding this processing to the end of the startup file
app.js

app.use(function (err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
        message: err.message,
        error: {}
    });
});

Then you need to check the API of mysql connector. Generally, it must have an exception handling mechanism.
I use mongoose. Add exception handling when declaring the connection.

mongoose.connection.on('error', function (err) {
    console.error('Mongoose connection error: ' + err);
});
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template