gpt4 book ai didi

mysql - 错误 : ER_BAD_FIELD_ERROR: Unknown column 'asd123' in 'field list' in node js

转载 作者:可可西里 更新时间:2023-11-01 06:48:01 26 4
gpt4 key购买 nike

当我尝试在 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 调用它,它会给我这样的错误 Error: ER_BAD_FIELD_ERROR: Unknown column 'asd123' in 'field list' ,请帮助

最佳答案

尝试下面的查询,变量'+userID+''+socketID+'修改为"'+userID+'""'+socketID+'":

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

关于mysql - 错误 : ER_BAD_FIELD_ERROR: Unknown column 'asd123' in 'field list' in node js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13487920/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com