日期:2014-05-16 浏览次数:20444 次
var mysql = require('mysql'); var connection = mysql.createConnection({ host : 'localhost', user : 'root', password : '123456', database : 'test' }) ,slice = [].slice ; var commonMethod = function(callback){ connection = mysql.createConnection(connection.config); connection.connect(); callback.call(connection,callback); connection.end(); }; var onerror = function(){ console.log(err); }; var query = function(){ var args = arguments; commonMethod(function(){ connection.query.apply(connection,args) .on('error',onerror); }); };