为什么受影响的行在更新/删除成功时返回0? [英] Why affected rows return 0 while update/delete success?

查看:40
本文介绍了为什么受影响的行在更新/删除成功时返回0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有陈述:

INSERT INTO infotbl(name, phone) VALUES('Alex', '9999999');

并进行更新:

UPDATE infotbl SET name = 'Alex Johnes', phone = '999 34356063' WHERE id = 1;

然后删除:

DELETE FROM infotbl WHERE id = 1;

在MySQL中,当我更新和删除行时,我已成功插入.但是我在Node中的代码返回受影响的行=0.为什么?.我的功能是在Node中更新和删除:

I've inserted successfully, when I update and delete rows has been change in MySQL. but my code in Node return affected rows = 0. Why?. There is my function to update and delete in Node:

function deleteCustomer (id, callback) {
        db.connection.query("DELETE FROM infotbl WHERE id=?", id, (err, result) => {
            if (err) throw err;
            if (result.affectedRows > 0)
                callback(true);
            else
                callback(false);
        });
    };

并更新功能:

function updateCustomer(id, name, phone, callback) {
    db.connection.query("UPDATE infotbl SET name = ?, phone = ? WHERE id = ?;", [name, phone, id], (err, result) => {
        if (err) throw err;
                if (result.affectedRows > 0)
                    callback(true);
                else
                    callback(false);
});
}

为什么节点成功执行数据库后返回0个受影响的行?

Why node return 0 affected rows when database executed successfully?

推荐答案

最可能的解释是,没有满足UPDATE和DELETE语句中条件的行.也就是说,没有id值等于1的行.

The most likely explanation is that there are no rows that satisfy the conditions in the UPDATE and DELETE statements. That is, there are no rows with id value equal to 1.

如果条件匹配一个或多个行,则UPDATE可能会影响零行,但是应用于该行的更改将导致无更改"……也就是说,被修改的列已经分配了值.

An UPDATE could affect zero rows if the conditions match one or more rows, but the changes applied to the row result in "no change"... that is, the columns being modified already have the values being assigned.

成功执行但影响零行的UPDATE或DELETE仍然被认为是成功的.

An UPDATE or DELETE that executes successfully, but affects zero rows, is still considered successful.

这篇关于为什么受影响的行在更新/删除成功时返回0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆