Reputation: 2659
I want to get the data from database. I tried like this but what happening here is that, I am getting the total number rows. But I want the total data. Can any one help me?
connection.on('connect',function(err){
if(err){
console.log(err)
}else{
var sql = "SELECT * FROM xxxxx";
var request = new Request(sql,
function(err,result){
if(err){
console.log(err);
}else{
console.log("hello:"+result)
}
});
connection.execSql(request);
}
});
I need the total data from database.
Upvotes: 1
Views: 77
Reputation: 91
You can do it, using pool, like this:
var mysql = require('mysql');
var pool = mysql.createPool({
host : 'localhost',
user : 'mysql username',
password : 'password',
database: 'database_name'
});
pool.getConnection(function(err, connection) {
connection.query('SELECT * FROM table',function(err,rows){
if (err) console.log('error!: '+err);
else console.log(rows);
} );
connection.release();
// Don't use the connection here, it has been returned to the pool.
});
Hope it helps
Upvotes: 2