catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

How could I use Medoo to use MYSQL md5 function? #566

Closed DaveSanchez closed 6 years ago

DaveSanchez commented 7 years ago

I'm hashing all my database ids for a more secure application, but I need to write queries like this:

UPDATE "users" SET "user_password" = '$2y$10$uCCGApw.KSarq17DhHtXse.BNswdUWP/X9W87kCCzkU2q9XytZX.a' WHERE md5("iduser") = 'c4ca4238a0b923820dcc509a6f75849b'

How could be this possible?, I wrote the next code but it's not generating what I want to:

$this->_app['medoo']->debug()->update('users',[ 'user_password' => $password ],[ 'md5(iduser)' => $user ]);

outputs:

UPDATE "users" SET "user_password" = '$2y$10$c7/8miGJ9zhUKDQherY0J.j4NiL4DE2ShfNIcvUUSl63yj3hSpENS' WHERE "md5" = 'c4ca4238a0b923820dcc509a6f75849b'

Please help!

sihar commented 7 years ago

I think you can't use update method. My suggestion, you can use query method with prepared statement like this

    $database->debug()->query(
    "UPDATE users SET user_password=:passwordnya WHERE md5('iduser')=:idnya", [
        ":passwordnya" => "this is passwordnya",
        ":idnya" => "this is id user"
    ]
)->fetchAll();

https://medoo.in/api/query

catfan commented 6 years ago

Check out the new feature raw object https://medoo.in/api/raw.