0
When I make a select in my bank MYSQL, I get the answer and I can display it to the user, but the problem is that this is not enough,just take the result and display it, I need for example to check if a given id has data in a table, and if not, do the INSERT.
This is my code on the server side.
app.post('/companies', function(req, res) {
console.log('enviado do app'+req.body.id);
let filter = '';
filter = ' WHERE id_companies=' + req.body.id;
execSQLQuery('SELECT * FROM companies' + filter, res);
"é aqui que eu preciso usar a variável results que eu recebo lá embaixo para continuar"
});
//inicia o servidor
app.listen(port);
console.log('API funcionando!');
function execSQLQuery(sqlQry, res){
const connection = mysql.createConnection({
host : '***************',
port : 1111,
user : '**************',
password : '************',
database : '****************'
connection.query(sqlQry, function(error, results, fields){
if(error)
res.json(error);
else
res.json(results);
connection.end();
console.log('executou!');
});
}
If anyone can help me, I’d appreciate it.