function db(callback){ var mysql = require('mysql'); var connection = mysql.createConnection({ host : 'localhost', user : 'root', password : '', port: '3306', database: 'test', }); connection.connect(); var sql = 'SELECT * FROM uer'; var sql1 = 'SELECT * FROM member'; //查 var rr; var tt; connection.query(sql,function (err, result) { if(err){ console.log('[SELECT ERROR] - ',err.message); return; } rr=JSON.stringify(result) //callback(rr); }); connection.query(sql1,function (err, result) { if(err){ console.log('[SELECT ERROR] - ',err.message); return; } tt=JSON.stringify(result) if (rr && tt) { callback(rr,tt); } }); /*connection.query(sql,function (err, result) { if(err){ console.log('[SELECT ERROR] - ',err.message); return; } var r=2; json=JSON.stringify(result) callback(json); });*/ connection.end(); } exports.db=db; var a; var b; var c; /*function callback1(type,result){ c[type]=result; if (c[1] && c[2]) { res.end(c); } }*/