Monday, 3 April 2017

Check if ROW already exists in Database using query > NodeJS

I've had this problem for a while now and I can't seem to figure it out, I've looked around on Stackoverflow but could only find either PHP or C# code matching my problem. I'm trying to check if a row exist, if it doesn't then send a message that it does not, if it does send a message that it does.

Here's my code,

query('SELECT * FROM `cases` WHERE `case`='+pool.escape(String(getCase)), function(err, row) {

    if(err) {
        logger.error('Error in DB');
        logger.debug(err);
        return;
    }else{

        console.log('Case row was found!');

    }

});

Also, getCase is a variable that I can change, but even when it's not in the database it seems to return Case row was found!



via Martijn Ebbens

No comments:

Post a Comment