当我尝试更新phpmyadmin中的表时收到此错误
谁能告诉我怎么了
这是 table
create table ms_registereduser(userID Varchar(10),socketID Varchar(255));
这是我的server.js
var http = require("http");
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '',
database : 'pushnotificationdb'
});
var userID = "1234567890",
socketID = "asd123";
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(1111);
connection.connect();
connection.query('callpushnotificationdb.spUpdateSocketID('+userID+','+socketID+');').on('end',function()
{
console.log('User '+ userID+' has updated his socketID to '+socketID);
});
connection.end();
这是我的spUpdateSocketID,以“//”作为分隔符
DROP PROCEDURE IF EXISTS spUpdateSocketID//
CREATE PROCEDURE spUpdateSocketID(IN userID Varchar(10) ,IN socketID Varchar(255))
BEGIN
set @userID = userID;
set @socketID = socketID;
set @s = CONCAT('UPDATE ms_registereduser SET socketID = @socketID WHERE userID = @userID');
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END//
如果我尝试像这样在phpmyadmin中调用该过程
call pushnotificationdb.spUpdateSocketID('1234567890','asd123');
它可以工作,但是如果我尝试从node.js调用它,则会给我这样的错误:ER_BAD_FIELD_ERROR:“字段列表”中的未知列“asd123”,请帮助
最佳答案
尝试以下查询,将变量'+userID+'
和'+socketID+'
修改为"'+userID+'"
和"'+socketID+'"
:
connection.query(
'callpushnotificationdb.spUpdateSocketID("'+userID+'","'+socketID+'");'
)
.on('end',function(){
console.log('User '+ userID+' has updated his socketID to '+socketID);
});