我将mysql安装到项目下的node_modules文件夹里,然后新建了一个demo.js的文件.
代码如下
console.log(‘正在连接MySQL…’); var client = require(‘mysql’).createClient({’host’:’localhost’,’port’:3306,’user’:’root’,’password’:’hhl0630’});
clientConnectionReady = function(client) { client.query('use node’, function(error, results) { if(error) { console.log('ClientConnectionReady Error: ' + error.message); client.end(); return; }else{ console.log(‘已经连接上MySQL…’); } clientReady(client); }); };
clientConnectionReady(client);
报错信息是
var client = require(‘mysql’).createClient({’host’:’localhost’,’port’:3306,’us
^
TypeError: Object #<Object> has no method ‘createClient’
at Object.<anonymous> (E:\www\microblog\demo.js:2:31)
at Module._compile (module.js:456:26)
at Object.Module._extensions…js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3