错误:ER_BAD_FIELD_ERROR:节点js中“字段列表”中的未知列“asd123”

时间:2012-11-21 06:56:52

标签: mysql sql node.js

我在尝试更新phpmyadmin中的表时收到此错误

任何人都可以告诉我有什么问题

这是表格

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',请帮助

2 个答案:

答案 0 :(得分:3)

尝试以下查询,将变量'+userID+''+socketID+'修改为"'+userID+'""'+socketID+'"

connection.query(
  'callpushnotificationdb.spUpdateSocketID("'+userID+'","'+socketID+'");'
)
.on('end',function(){
  console.log('User '+ userID+' has updated his socketID to '+socketID);
});

答案 1 :(得分:0)

试试这个:

DROP PROCEDURE IF EXISTS spUpdateSocketID//

CREATE PROCEDURE spUpdateSocketID(IN _userID VARCHAR(10) ,IN _socketID VARCHAR(255))
BEGIN
UPDATE ms_registereduser SET socketID = _socketID WHERE userID = _userID;
END//

将您的程序重新编写为下面的mentioed并尝试运行它:

DROP PROCEDURE IF EXISTS spUpdateSocketID//

CREATE PROCEDURE spUpdateSocketID(IN userID VARCHAR(10) ,IN socketID VARCHAR(255))
BEGIN
SET @s = CONCAT("UPDATE ms_registereduser SET socketID = '", socketID, "' WHERE userID = '", userID, "'");
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END//