有人可以解释一下为什么我不能将 rows 对象传递给 clubs 变量吗?
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '',
database : 'test'
});
var competition_feed = 'England';
var season_id = 2014;
var clubs = {};
connection.connect();
connection.query('SELECT * FROM clubs WHERE competition_feed=\''+competition_feed+'\' AND season_id='+season_id+';', function(err, rows, fields) {
if (err) throw err;
clubs = rows;
});
console.log(clubs);
connection.end();
看来我错过了一些关于变量和范围的东西。请帮忙 :)