I am trying to validate user using below code:
function validateUser(adminEmailId, adminPassword) {
try{
console.log('email id: '+adminEmailId+' password: '+ adminPassword);
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'somePassword',
database: 'someDatabase'
});
var query = connection.query('select id from AdminData where adminEmail = "'+adminEmailId+'" AND adminPassword = "'+adminPassword+'"');
console.log('query: ' + query);
query.on('error', function(error){
console.log('A db error occurred: '+error);
});
query.on('result', function(result){
console.log('some result: '+ result);
if(result.id === null) {
console.log('user not found');
}
else
{
console.log('user found :)');
}
});
}
catch (ex) {
console.log('some exception ' + ex);
}
}
The last two logs which it is printing in console are -
email id: [email protected] password: gfdgdf
query: [object Object]
It should have printed -
user not found
// OR
user found :)
I tried verifying if SQL is running properly or not by firing this in command line:
mysql -h127.0.0.1 -uroot -p
It showed me error:
Command not found
So I updated the path by using below command:
export PATH="/usr/local/mysql/bin:$PATH"
Then I was able to use mysql from command line, but still there is no success achieved in Node.js code :(
Any suggestions?
PDOone: php.net/manual/en/pdostatement.fetchobject.php. Here for ( deprecated )MySQL: php.net/manual/en/function.mysql-fetch-object.php. All php, sorries. Thought would help!