2014-12-02 66 views
2

我無法訪問MySQL查詢回調裏面的discovered_matches數組,怎麼回事?無法在NodeJS中使用全局變量MySQL

我遇到了一個'TypeError:Can not read''null'錯誤消息在console.log(coming_matches [1]);表示該變量因爲某種原因被重置的行(猜測,我對JavaScript不太熟悉)?

var regex = regex code.. 

while ((upcoming_matches = regex.exec(body)) != null) { 
    HLTVID = upcoming_matches[1].split("-");  

    connection.query('SELECT * FROM `csgo_matches` WHERE HLTVID=' + HLTVID[0], function(err, rows, fields) { 
     if (err) throw err; 
     console.log(upcoming_matches[1]); 
    }); 
} 

回答