Db::insertOrUpdate
Usage
void Db::insertOrUpdate(string $table_name, [ ... $args ])Description
Insert or update a record into a database table.Parameters
Parameter | Required | Type | Description |
---|---|---|---|
$table_name | Yes | string | The table name to insert or update record within. |
$args | No | List of either associative arrays or objects, each of which represents one record to insert or update. If the provided records have the same id# / value of primary key column as a database record the record will be updated, and otherwise a new record will be inserted. |
Examples
Insert or Update
// Add new user
$this->db->insertOrUpdate('users', [
'name' => 'John Smith',
'email' => '[email protected]'
]);
// Get userid
$userid = $this->db->insertId();
// Update the existing record
$this->db->insertOrUpdate('users', [
'id' => $userid,
'name' => 'Mike Smith'',
'email' => '[email protected]'
]);
// This will result in one record with the name 'Mike Smith'.