ze\row::set()
ze\row::set($table, $values, $ids, $ignore = false, $ignoreMissingColumns = false, $markNewThingsInSession = false)
Inserts or updates a row in a given table in the database.
If a row in the table matches, then that row will be updated with $values
. Otherwise a row will be inserted in the table containing the values of both $values
and $ids
.
If your primary key column is an auto-increment, then entering either an id of zero or an id that doesn't match will force this function to insert a new row. The id of this new row will be the auto-increment value; regardless of the value you provided.
Entering an empty array will force this function to insert a row. (Note that this is slightly different behaviour to the rest of the Database Functions, where entering an empty array will match every row in the table.)
If page caching is in use on a site, the cache will be cleared depending on the tables or rows affected.
$table
The name of a table to insert into. To meet our guidelines this should be one of your own Plugin's tables, as you may not directly modify a table belonging to another Plugin or the core.
$values
An associative array of keys (column names) to values to set; see Format of $id and $values for Database Functions for details. You can pass an empty array into $values, if you just want to make sure that a row matched by $ids exists in the table, but don't actually want to change any of the columns.
$ids
An associative array of keys (column names) to values; see Format of $id and $values for Database Functions for details.
If a row was inserted, then this function will return the result of a mysqli_insert_id()
call to give you the primary key.
The primary key will also be returned when updating a row in the table, even if the primary key was not specified in the $ids array.
This only applies to tables with a single-column primary key.
setRow(MY_ANIMAL_MANAGER_PREFIX. 'animals', array('name' => 'Chicken'), array('id' => 7));
If a row exists in the animals table with an id of 7, its name is updated to "Chicken".
If a row with that id did not exist, a new one will be inserted in with a name of "Chicken". (Note that the function will also attempt to set the id of that row to 7, however if the id column has an auto-increment on it then this will be ignored.)