Medoo - Updating table row matching multiple field

2.2k views Asked by At

I am using Medoo. the update below works fine with single field match. I want to update data if match with clientId and businessCity.

$database->update("clientInfo", array(
     "businessName" => $_POST['businessName'],
     "contactName" => $_POST['contactName'],
     "businessEmail" => $_POST['businessEmail'],
     "businessPhone" => $_POST['businessPhone'],
     "businessWebsite" => $_POST['businessWebsite'],
     "businessAddress" => $_POST['businessAddress'],
     "businessAddress2" => $_POST['businessAddress2'],
     "businessCity" => $_POST['businessCity'],
     "businessState" => $_POST['businessState'],
     "businessZip" => $_POST['businessZip']
), array(
    "clientId" => $_POST['clientId'],
    "businessCity" => $_POST['businessCity'],
));

I tried like this. but not working for me.

3

There are 3 answers

0
Deror On

echo $database->last_query();

use this function to check out the SQL query performed for debug.

0
Angolao On

Read about the Relativity Condition from Medoo documentation: http://medoo.in/api/where

Just add AND connector to each value.

$database->update("clientInfo", array(
     "businessName" => $_POST['businessName'],
     "contactName" => $_POST['contactName'],
     "businessEmail" => $_POST['businessEmail'],
     "businessPhone" => $_POST['businessPhone'],
     "businessWebsite" => $_POST['businessWebsite'],
     "businessAddress" => $_POST['businessAddress'],
     "businessAddress2" => $_POST['businessAddress2'],
     "businessCity" => $_POST['businessCity'],
     "businessState" => $_POST['businessState'],
     "businessZip" => $_POST['businessZip']
), array(
    'AND' => array(
        "clientId" => $_POST['clientId'],
        "businessCity" => $_POST['businessCity'],
    )
));
0
Valix85 On

Example:

$datas = $db->update( "meta" , ["metalabel"=>$label[0][0]], ["AND"=>["metakey"=>"Collection", "metavalue"=>$_POST["metavalue"]] ]  );

you must set an array with logic operator (AND or OR) and as the first value of this you must set another array...see my example above