mysql - Terminating a callback in nodejs -
i new nodejs. using mysql
node module. how use it:
var connection = mysql.createconnection({ host: 'localhost', user: 'root', password: '', database: 'sample' }); connection.connect(function (err) { if (!err) { console.log("database connected ... \n\n"); } else { console.log("error connecting database ... \n\n"); } }); var post = {personid: 1, name: 'prachi', city: 'blore'}; var query = connection.query('insert persons set ?', post, function(error, result) { if (error) { console.log(error.message); } else { console.log('success'); } }); console.log(query.sql);
this node code works functionally. in, adds data table. doesn't terminate. mistake making?
take closer @ official documentation, have close connection :
var mysql = require('mysql'); var connection = mysql.createconnection({ host : 'localhost', user : 'me', password : 'secret' }); connection.connect(); connection.query('select 1 + 1 solution', function(err, rows, fields) { if (err) throw err; console.log('the solution is: ', rows[0].solution); }); connection.end();
Comments
Post a Comment