2012-12-28 74 views
4

我運行的代碼在節點的MySQL的教程部分,它給我的錯誤得到錯誤,而正在運行的節點,MySQL的教程

代碼

var MySQLPool = require("mysql-pool").MySQLPool; 
var pool = new MySQLPool({ 
    poolSize: 4, 
    user:  'root', 
    password: 'root', 
    database: 'test' 
}); 

pool.query("SELECT 'Hello, World!' AS hello", function(err, rows, fields) { 
    if(err) throw err; 
    console.log(rows[0].hello); 
}); 

for(var i = 0; i < 10; ++i) { 
    pool.query("SELECT SLEEP(2), ? AS i", [i], function(err, rows, fields) { 
    if(err) throw err; 
    console.log("Slept: " + rows[0].i); 
    }); 
} 

錯誤:

/home/comapq/Works/Nodejs/Codes/node_modules/mysql-pool/lib/mysql-pool/pool.js:158 for(var key in Client.prototype) { ^ TypeError: Cannot read property 'prototype' of undefined at MySQLPool._populate (/home/comapq/Works/Nodejs/Codes/node_modules/mysql-pool/lib/mysql-pool/pool.js:158:23) at new MySQLPool (/home/comapq/Works/Nodejs/Codes/node_modules/mysql-pool/lib/mysql-pool/pool.js:44:7) at Object. (/home/comapq/Works/Nodejs/Codes/test-mysql-3.js:2:12) at Module._compile (module.js:449:26) at Object.Module._extensions..js (module.js:467:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.runMain (module.js:492:10) at process.startup.processNextTick.process._tickCallback (node.js:244:9)

回答

5

經過一番研究,我發現了這個問題。你可能安裝了這樣的mysql:

npm install mysql 

這抓住了最新的mysql包2.0.0-alpha5(開發階段,主要是未經測試)。你需要安裝最新的穩定版本的mysql:

npm install [email protected] 
+0

是的,解決了它謝謝 –