1
如何从节点mysql返回结果 https://github.com/felixge/node-mysql 我试图访问函数外部返回的结果。如何从节点mysql返回结果
var mysql = require('mysql');
var TEST_DATABASE = 'zenoir';
var TEST_TABLE = 'tbl_sessions';
var client = mysql.createClient({
user: 'root',
password: 'secret',
});
var outer = 20;
client.query('USE '+TEST_DATABASE);
client.query(
'SELECT ses_title FROM '+TEST_TABLE,
function selectCb(err, results, fields) {
if (err) {
throw err;
}
var boom = results;
var rooms = [];
var index = 0;
var name = 'session';
for(var b in boom){
rooms[b] = {};
rooms[b][name + index] = boom[b]['ses_title'];
index += 1;
}
var exe = {};
for(var mon in rooms){
for(var zeb in rooms[mon]){
exe[mon] = rooms[mon][zeb];
}
}
outer = exe; //I want to access the exe variable outside the function scope
client.end();
}
);
console.log(outer); //I still get the initial value 20 in here.
从未听说过异步? – Shikiryu 2012-03-21 11:49:04
我还没有听说过它。 – user225269 2012-03-21 11:57:02