我正在尝试使用node.js插入一些数据.我写了以下代码,并通过npm安装了MysqL支持,但是我未能插入表中.
这是我的代码:
var MysqL = require('MysqL');
function BD() {
var connection = MysqL.createConnection({
user: 'root',password: '',host: 'localhost',port: 3306,database: 'nodejs'
});
return connection;
}
app.post("/user/create",function(req,res) {
var objBD = BD();
var post = {
username: req.body.username,password: req.body.password
};
objBD.query('INSERT INTO users VALUES ?',post,function(error) {
if (error) {
console.log(error.message);
} else {
console.log('success');
}
});
});
错误信息是:
You have an error in your sql Syntax; check the manual that corresponds to your MysqL server version for the right Syntax to use near .’username’ = ‘Test’,‘password’ = ‘test’ at line 1
我的错误是什么?