var mysqldb=require(‘node-mysql’); var db=mysqldb.DB({ host:’localhost’, user:’root’, password:’123456’, database:’mynode’, //connectionLimit:50 }); 写了一段这个就报错this._init.aaply(this.arguments),怎么回事,nodejs人生的第一步就感到困难
github上的例子不是这样写的吗: var mysql = require(‘mysql’); var connection = mysql.createConnection({ host : 'localhost’, user : 'me’, password : 'secret’, database : ‘my_db’ });
connection.connect();
// 查询数据 var mysql = require(‘mysql’); var obj = { host:’localhost’, port:3306, database: ‘mydb’, multipleStatements: true, user:’root’, password:’lw123’ }; var tableName = "myclass"; var connection = mysql.createConnection(obj);
connection.connect (function (err){ if(err) console.log(“与mysql数据库连接失败”); else{ console.log(“与mysql连接成功”); queryData(); } });
function queryData (){ /connection.query("select * from ??",[tableName],function(err,result){ if(err) console.log(“查询数据失败”); else{ console.log(result); connection.end(); } });/ connection.query("select * from "+tableName,function(err,result){ if(err) console.log(“查询数据失败”); else{ // console.log(typeof result); // console.log(result); result.forEach(function (item){ if (item.name == null){ console.log(item); } }); connection.end(); } }); } 以前写的demo你看看。。