E
E
expeerd2015-07-19 00:17:12
MySQL
expeerd, 2015-07-19 00:17:12

Why is mysql+node.js acting weird?

For some unknown reason, this code does not work in a bunch of node.js and mysql:

var sql = 'DELETE FROM `test` WHERE id = "'+results[0]['id']+'"';
connection.query(sql);

At the same time, if I log the final request to the console, copy it manually to phpmyadmin, and actually execute it, then everything works. What to do with it?
mysql this one: https://github.com/felixge/node-mysql/ , everything works on localhost, without these two lines everything is ok, here is a piece of relief:
connection.query('SELECT * FROM `test` WHERE `hold` = "1" AND `status` = "0"', function(err, results) {
    
         if (err) throw err; 
         if (results[0]['botStop'] == '1') {
       	   clearInterval(interval);
           console.log('stopped')
         }
         else {
           var id = results[0]['id'];
           var sql = 'DELETE FROM `test` WHERE id = "'+results[0]['id']+'"';
           console.log(sql);
           connection.query(sql);
           console.log('trade '+id+' started');
         }
        });

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Timur Shemsedinov, 2015-07-19
@expeerd

Because there is no function in which the result of the query will be returned, can you tell me what is the result of DELETE? And I will answer you that this result is provided for connection.query and even DELETE can return an error, and if there is nowhere to return it, then the function call format is violated, it has every right not to work. Also, for the sake of Allah, don't glue SQL with strings.

var sql = 'DELETE FROM test WHERE id = ?';
connection.query(sql, [results[0]['id']], function (err) {
  if (err) console.log('Error query');
});

A
Alexander Litvinenko, 2015-07-19
@edli007

Have you heard of injections?
It's hard to say why it doesn't work from such a small piece of code, without even knowing what library you used for the muscle.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question