Answer the question
In order to leave comments, you need to log in
How to stop sql query?
There is a code:
var sql = require("mysql");
var connection = sql.createConnection({
host: 'localhost',
user: 'root',
password: 'password',
database: 'chat'
});
app.get('/', function(req, res) {
connection.connect();
var loga = "kulonful";
connection.query('select * from users where login = "'+loga+'"', function(err, result){
if(err) { res.send('Произошла критическая ошибка'); }
// здесь
res.send(result);
});
})
Answer the question
In order to leave comments, you need to log in
Because connection.connect shouldn't be inside app.get, what do you think should happen if multiple users access your server at the same time? connection you have a global variable, each of the users will try to connect to it, although it is already connected and is processing another user's request at this time.
You either need to take out connect and make a connection as soon as the script starts, or use a connection pool and allocate connections from it to each user.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question