Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why mysql returns true when false

Tags:

php

mysql

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.

like image 628
Alrasyidin Kartadinata Avatar asked Mar 12 '23 01:03

Alrasyidin Kartadinata


1 Answers

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.

like image 104
tadman Avatar answered Mar 20 '23 09:03

tadman