Wednesday, 8 February 2017

Difference between CreateConnection and poolConnection in NodeJS

Difference between CreateConnection and poolConnection in NodeJS


MySQL CreateConnection Example
var mysqlClient = mysql.createConnection({
         host     : 'localhost',
         user     : 'root',
         password : '',
         database : 'mydb'
}); 
mysqlClient.connect();
mysqlClient.query(
'SELECT id,name,email FROM `cmf_users` WHERE id = ' + data.uid, function (error, results, fields) {
    console.log(results);
});


MySQL PoolConnection Example
var mysqlPool = mysql.createPool({
       connectionLimit : 10,
       host     : 'localhost',
       user     : 'root',
       password : '',
       database : 'mydb'
});
mysqlPool.getConnection(function(err, mysqlConn) {
mysqlConn.query(
    'SELECT id,name,email FROM `cmf_users` WHERE id = ' + data.uid, function (error, results, fields) {
    console.log(results);
    }
    )
});

No comments :

Post a Comment