简体   繁体   English

为什么mysql在false时返回true

[英]why mysql returns true when false

I have problem. 我有问题。 like this, this code DELETE FROM guru WHERE id=2 return true when in database mysql . 像这样,这个代码DELETE FROM guru WHERE id=2在数据库mysql返回true。 only there data with id=1 in mysql . 只有mysql id = 1的数据。 should return false because id=2 in syntax above. 应该返回false,因为在上面的语法中id = 2。 so I confuse, help me please. 所以我很困惑,请帮帮我。 I'm sorry my English less fluent. 对不起,我的英语不太流利。

The DELETE operation will be successful if the syntax is correct and the table guru exists in the database you're connected to. 如果语法正确并且表guru存在于您连接的数据库中,则DELETE操作将成功。 A false is what happens specifically when a query encounters an error and requesting a deletion on rows that don't exist is not an error. 一个false是特别是当一个查询遇到错误 ,并请求在不存在的行删除是不是一个错误会发生什么。

What you want to do is check how many rows were affected by your query, as if that's zero then it didn't do anything. 你想要做的是检查你的查询影响了多少行,好像它是零然后它没有做任何事情。

MySql delete query returns true in case of success and false in case of failures. MySql delete查询在成功时返回true,在失败时返回false。 If there is no row meeting the criteria then also it returns true. 如果没有符合条件的行,那么它也返回true。

In your case you will have to get the No of deleted rows to find out whether any row has deleted or not. 在您的情况下,您将必须获取No of deleted rows以确定是否已删除任何行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM