I want to check if some date exist in a table, if not I want to insert it. I have done this in other project and there it works but now i don't know why it doesn't work.
var mysql = require('mysql');
var connection = mysql.createConnection({
host : '',
user : '',
password : '',
database : ''
});
[..]
connection.query('SELECT id FROM users [...]', function(err, results) {
if (err) {
throw err;
} else if (results.length==1) {
callback(null, results[0].id);
} else {
console.log('before insert');
connection.query('INSERT INTO users SET ?', user, function(err, result) {
console.log('insert');
if (err) throw err;
});
}
});
The query with INSERT doesn't work, but if i get that query out of the SELECT query then it works.
Doesn't matter if it is INSERT or other query.
In console I only see: 'before insert' and no error.
This query it's in a loop.