Db\Adapter::update

public boolean update (string | array $table, array $fields, array $values, [string | array $whereCondition], [array $dataTypes])

Updates data on a table using custom RBDM SQL syntax

//Updating existing robot
 $success = $connection->update(
 "robots",
 array("name"),
 array("New Astro Boy"),
 "id = 101"
 );

 //Next SQL sentence is sent to the database system
 UPDATE `robots` SET `name` = "Astro boy" WHERE id = 101

 //Updating existing robot with array condition and $dataTypes
 $success = $connection->update(
 "robots",
 array("name"),
 array("New Astro Boy"),
 array(
     'conditions' => "id = ?",
     'bind' => array($some_unsafe_id),
     'bindTypes' => array(PDO::PARAM_INT) //use only if you use $dataTypes param
 ),
 array(PDO::PARAM_STR)
 );

Warning! If $whereCondition is string it not escaped.

doc_Phalcon
2016-10-16 09:48:54
Comments
Leave a Comment

Please login to continue.