catfan / Medoo

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

update() function , updating multiple fields #201

Closed ksparakis closed 8 years ago

ksparakis commented 9 years ago

I ran into this issue where instead of being able to update 2 fields with 1 function call , I needed to make two separate calls. This might possibly be an issue with using a MySQL Function and adding the "#" in front , or maybe this is just not supported yet as of (0.9.8).

This is what works for me: (note: Im using enums so wherever you see TABLE::SOMETHING or KEY::SOMETHING all it is, is a string)

$medoo->update(TABLE::REG, [ "#".KEY::REG_DATE_MODIFIED => "NOW()"], ["AND" => [KEY::REG_EMAIL => $email, KEY::REG_STATUS => "A"]]); $medoo->update(TABLE::REG, [KEY::REG_STATUS => "D"], ["AND" => [KEY::REG_EMAIL => $email, KEY::REG_STATUS => "A"]]);

This didn't work for me and I believe should be added or am I doing something wrong?

$medoo->update(TABLE::REG, ["AND" => [KEY::REG_STATUS => "D", "#".KEY::REG_DATE_MODIFIED => "NOW()"]], ["AND" => [KEY::REG_EMAIL => $email, KEY::REG_STATUS => "A"]]);

Just wanted to bring this up, If I have time to look at the source code and edit it, Ill gladly share my solution.

Jervelund commented 9 years ago

From: http://medoo.in/api/update You should only use the two dimensional array structure for the $where parameter. The $data should just be kept as a single dimensional array:

$medoo->update(TABLE::REG, [KEY::REG_STATUS => "D", "#".KEY::REG_DATE_MODIFIED => "NOW()"], ["AND" => [KEY::REG_EMAIL => $email, KEY::REG_STATUS => "A"]]);