Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating with where Condition. #1012

Open
tayyab82977 opened this issue Sep 16, 2021 · 2 comments
Open

Updating with where Condition. #1012

tayyab82977 opened this issue Sep 16, 2021 · 2 comments

Comments

@tayyab82977
Copy link

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.

@unikoca
Copy link

unikoca commented Jan 7, 2022

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.

@larananas
Copy link

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants