1

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.

1
  • which library do you use? connection.execSql Commented Jun 16, 2015 at 10:39

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.