我有这个功能在DB中注册一个新用户:
this.registerUser = function(username,password,name,picture){
client.query('INSERT INTO' + USER +'SET username=?,passsword=?,name=?,picture=?',[username,password,name,picture],
function(err){
if(err){
throw err;
}
});
}
这是用于从另一个模块调用该函数的行:
var data = new db.dataBase('root','root');
data.registerUser("a","a","a","a");
这是MySQL表:
client.query(
'CREATE TEMPORARY TABLE IF NOT EXISTS '+USER+
'(username VARCHAR(255), '+
'password VARCHAR(255), '+
'name VARCHAR(255), '+
'picture VARCHAR(255), '+
'PRIMARY KEY(username))'
);
由于某些未知原因(对我而言)我收到此错误:
Error: 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='a',password='a',name='a',picture='a'' at line 1
我不知道我在这里做错了什么,请帮助。
谢谢!
答案 0 :(得分:3)
我认为它有空格的问题,:
//add space after INTO and before SET
client.query('INSERT INTO ' + USER +' SET username=?,passsword=?,name=?,picture=?',[username,password,name,picture],
希望有所帮助