我寫了一個nodejs Server。JavaScript/CoffeScript返回「[object Object]」的右值
app.get("/admin", function (req, res) {
var connection, value;
connection = mysql.createConnection({
host: "******",
user: "*****",
password: "****",
database: "YaAMP",
insecureAuth: true
});
value = mySQLgetValue("SELECT property, value FROM config WHERE property = 'primeMult'", connection);
console.log("Return Value" + value); //returns "[object Object]"
connection.end();
return res.render("admin", {
title: "YaAMP"
});
});
而一個mySQLgetValue
函數來獲取從MySQL數據庫,這應該從數據庫返回的特定值的值。
mySQLgetValue = function (queryString, connection) {
var value;
value = 0;
return connection.query(queryString, function (err, rows, fields) {
console.log("Value " + rows[0].value); //Returns correct value
return value += rows[0].value;
});
};
在mySQLgetValue
功能console.log
返回從DB正確的值。但函數調用返回一個Object
和console.log
打印「[對象對象]」。
出了什麼問題?
'mySQLgetValue'是否真的同步? – 2013-04-29 15:06:22