node-mysql insert产生no method replace错误
发布于 12 年前 作者 cattail2012 6375 次浏览 最后一次编辑是 8 年前
	connection.query( "INSERT INTO staff SET ?",staff,function(err,result){
	if( !err ){
		console.log(result);
	}
});

产生错误

   val = val.replace(/[\0\n\r\b\t\\\'\"\x1a]/g, function(s) {
} has no method 'replace'
   at Object.escape (/home/cattail/project/databasedesign/3/node_modules/mysql/lib/protocol/SqlString.js:33:13)
at Object.objectToValues (/home/cattail/project/databasedesign/3/node_modules/mysql/lib/protocol/SqlString.js:95:48)
at Object.escape (/home/cattail/project/databasedesign/3/node_modules/mysql/lib/protocol/SqlString.js:29:24)
at /home/cattail/project/databasedesign/3/node_modules/mysql/lib/protocol/SqlString.js:61:22
at String.replace (native)
at Object.format (/home/cattail/project/databasedesign/3/node_modules/mysql/lib/protocol/SqlString.js:56:14)
at Connection.format (/home/cattail/project/databasedesign/3/node_modules/mysql/lib/Connection.js:99:20)
at Connection.query (/home/cattail/project/databasedesign/3/node_modules/mysql/lib/Connection.js:64:22)
at /home/cattail/project/databasedesign/3/views.js:54:13
at IncomingMessage.<anonymous> (/home/cattail/project/databasedesign/3/manage.js:49:16)

请问这是怎么回事?我搜索了一些资料,是在不明白错在了哪里,我尝试不使用node-mysql INSERT INTO table SET这种形式,而是用INSERT INTO table (a,b,c) VALUES(c,d,e)这时候就可以正常插入数据了!!!

2 回复
connection.query( "INSERT INTO staff SET staff=?",staff,function(err,result){
if( !err ){
    console.log(result);
}

});

感觉是这样写吧!

请看这里

不是的,上面链接的代码就是这样的

回到顶部