[英]How can I make a update prepared statement work in JavaScript in Node JS
.then(function (val) {
var roleId = roleArr.indexOf(val.role) + 1;
db.query(
'UPDATE employee SET role_id = ? WHERE first_name = ? AND last_name = ?;',
[roleId, val.firstname, val.lastName],
function (err) {
if (err) throw err;
console.table(val);
startPrompt();
}
);
});
This code comes from an inquirer statement.此代码来自询问者声明。 The roleID, val.firstname, and val.lastName are good variables because they are tested elsewhere in the program. roleID、val.firstname 和 val.lastName 是很好的变量,因为它们在程序的其他地方进行了测试。 The update statement is not updating though.虽然更新语句没有更新。 I tried it with doublequotes around the where statement variables but that doesn't work.我尝试在 where 语句变量周围加上双引号,但这不起作用。 What am I doing wrong?我究竟做错了什么? The same statement works in a mysql shell.相同的语句适用于 mysql shell。
I changed the code to get the id of the name I wanted to change instead of matching a first_name and last_name.我更改了代码以获取我想要更改的名称的 ID,而不是匹配 first_name 和 last_name。
var nameArr = [];
function Name() {
db.query(
"SELECT * FROM employee",
function (err, res) {
if (err) throw err;
for (var i = 0; i < res.length; i++) {
nameArr.push(res[i].first_name + " " + res[i].last_name);
}
});
return nameArr;
}
and和
var nameId = nameArr.indexOf(val.name) + 1;
Then I used the Name() to get the choices for the inquirer question.然后我使用 Name() 来获取询问者问题的选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.