Medoo icon indicating copy to clipboard operation
Medoo copied to clipboard

Updating with where Condition.

Open tayyab82977 opened this issue 3 years ago • 2 comments

Information

  • Version of Medoo:
  • MySQL
  • Linux

Describe the Problem User table is not updating with a return false. Because in the database status is already 1. If the update input is the same as the database it is returning false without reading where condition. It makes where condition useless.

Detail Code

            $update = $this->db->update("user", ["status" =>1], [
                "status[!]" => 2,
                "id" => $user->id, 
            ]);
if (!$update->rowCount()) return false;
       

Expected output The update should be happening on the USER table because in where condition I have put status not equals 2. Condition it should reach only with where mainly not the selection.

tayyab82977 avatar Sep 16 '21 12:09 tayyab82977

if you do your statement in pure mysql (ie: using phpmyadmin per example), you'll find that the datas aren't updated. So it's not a problem with this library (if i understand your problem correctly).

In my case when i do an update, i always pass the date (Y/m/d H:i:s) in a field named 'date_modified' so it's always update. In your case it could be :

            $update = $this->db->update("user", ["status" =>1], [
                "status[!]" => 2,
                "id" => $user->id,
                "date_updated"=> date('Y/m/d H:i:s')
            ]);

Hope that's help.

unikoca avatar Jan 07 '22 19:01 unikoca

Hi @tayyab82977, for me @unikoca solution is the proper way to do it even in the case date_updated field would have no other interest for you. It's that or a field with random data in it, at least update date have an interest and is nice to have. It will make your code work as needed :)

larananas avatar Aug 18 '23 11:08 larananas