我有以下代码,它应该更新服务表中第31行的url列:
connection.getConnection(function(err, connection) {
if (err) {
console.log(err);
}
const query = "update services set ? where ?;";
const params = [{ url: "www.test.com" }, { id: 31 }];
connection.query(query, params, function(error, rows, fields) {
if (error) {
console.log("failed");
}
console.log("success");
});
console.log(mysql.format(query, params));
connection.release();
});当我运行它时,查询没有运行,数据库保持不变。只有以下内容会记录在控制台中:
update services set `url` = 'www.test.com' where `id` = 31;这让我感到困惑,因为我希望“成功”或“失败”都会紧随其后。所以不会抛出错误。查询也可以直接在DB中运行(如果复制并粘贴到工作台中)。如果我将查询替换为以下内容:
connection.query("select curdate();", function(error, rows, fields) {然后我就得到了我在控制台中所期望的结果:
update services set `url` = 'www.test.com' where `id` = 31;
success有人能解释一下这里出了什么问题吗?
发布于 2020-02-05 10:56:37
好的..。问题出在我的MYSQL DB上。我注意到,在等待了一分钟之后,抛出了一个错误:'ER_LOCK_WAIT_TIMEOUT',这让我开始查看数据库。运行“show open tables where in_use>0;”显示正在锁定的表。原因-以某种方式自动提交设置已更改。天知道我是怎么做到的--也许是不小心点击了我的数据库管理工具。将该设置恢复为true,一切都会再次正常工作。
https://stackoverflow.com/questions/60066176
复制相似问题