无法使用Node.JS将null值发送到MySQL数据库 [英] Can't send the value of null to MySQL database using Node.JS
问题描述
我正在尝试使用Node.JS将 null
发送到我的MySQL数据库:
I'm trying to send null
to my MySQL database using Node.JS:
con.query("INSERT INTO Routes (routeTrigger) VALUES ( " + null + " )", {title: 'test'}, function(err, result) {
if (err) throw err;
});
但在查看数据库时,更新后的值为'null'
。数据库的 NULL
应该读取 NULL
。如果我发送大写 NULL
,那甚至不起作用(在Node.JS中)。如果我发送'NULL'
它发送字符串NULL,而不是数据库的 NULL
。
But when looking in the database, the updated value reads 'null'
. The database's NULL
is supposed to read NULL
. If I send capital NULL
instead, that doesn't even work (in Node.JS). If I send 'NULL'
it sends the string "NULL", and not the database's NULL
.
推荐答案
JavaScript的 null
与SQL的 Null不同/ code>。你想要(在你的情况下,使用原始SQL字符串)一个字符串:
JavaScript's null
is not the same as SQL's Null
. You want (in your case, using raw SQL strings) a string:
con.query("INSERT INTO Routes (routeTrigger) VALUES ( null )", {title: 'test'}, function(err, result) {
if (err) throw err;
});
但请注意,这会创建一个完全 null $ c $的行C>。这是可能的,但它不太可能你想要的。
But note that that creates a row that's entirely null
. Which is possible, but it's unlikely what you want.
你究竟想做什么?
这篇关于无法使用Node.JS将null值发送到MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!