Version: v2.3.0
update
Update records in a table.
update($table, $data, $where)
table [string]
The name of the table.
data [array]
The column-value pairs to update.
where [array] (optional)
The WHERE clause used to filter the records to be updated.
Return Value
[PDOStatement] The PDOStatement instance for the executed query.
Like
insert(), this method supports array serialization and automatic type detection. It also supports [+], [-], [*], and [/] operators for arithmetic updates.class Foo {
var $bar = "cat";
public function __wakeup()
{
$this->bar = "dog";
}
}
$object_data = new Foo();
$fp = fopen($_FILES[ "file" ][ "tmp_name" ], "rb");
$database->update("account", [
"type" => "user",
// Increase all ages by 1.
"age[+]" => 1,
// Decrease all levels by 5.
"level[-]" => 5,
// Multiply all scores by 2.
"score[*]" => 2,
// Array value.
"lang" => ["en", "fr", "jp", "cn"],
// Array value encoded as JSON.
"lang [JSON]" => ["en", "fr", "jp", "cn"],
// Boolean value.
"is_locked" => true,
// Object value.
"object_data" => $object_data,
// Large Objects (LOBs).
"image" => $fp
], [
"user_id[<]" => 1000
]);
// `update()` returns a PDOStatement, so you can call its methods for additional details.
$data = $database->update("account", [
"age[+]" => 1
], [
"user_id[>]" => 100
]);
// Returns the number of rows affected by the last SQL statement.
echo $data->rowCount();
// Reference: https://php.net/manual/en/class.pdostatement.php