简体   繁体   中英

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 . only there data with id=1 in mysql . should return false because id=2 in syntax above. 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. 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.

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. If there is no row meeting the criteria then also it returns true.

In your case you will have to get the No of deleted rows to find out whether any row has deleted or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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