update() public méthode

Automatically applies [[Solar_Sql_Adapter::quote() | ]] to the data values for you.
public update ( string $table, array $data, string | array $where ) : integer
$table string The table to udpate.
$data array An associative array where the key is the column name and the value is the value to use for that column.
$where string | array The SQL WHERE clause to limit which rows are updated.
Résultat integer The number of rows affected.
Exemple #1
0
 /**
  * 
  * Updates an existing session-data row in the database.
  * 
  * @param string $id The session ID.
  * 
  * @param string $data The serialized session data.
  * 
  * @return bool
  * 
  * @todo Should we log caught exceptions?
  *
  */
 protected function _update($id, $data)
 {
     $cols = array($this->_config['updated_col'] => date('Y-m-d H:i:s'), $this->_config['data_col'] => $data);
     $where = array("{$this->_config['id_col']} = ?" => $id);
     try {
         $this->_sql->update($this->_config['table'], $cols, $where);
         return true;
     } catch (Solar_Sql_Exception $e) {
         // @todo log this somehow?
         return false;
     }
 }
 /**
  * 
  * Updates rows in the model table and deletes cache entries.
  * 
  * @param array $data The row data to insert.
  * 
  * @param string|array $where The WHERE clause to identify which rows to 
  * update.
  * 
  * @return int The number of rows affected.
  * 
  * @throws Solar_Sql_Exception on failure of any sort.
  * 
  * @see Solar_Sql_Model_Cache::deleteAll()
  * 
  */
 public function update($data, $where)
 {
     if (!is_array($data)) {
         throw $this->_exception('ERR_DATA_NOT_ARRAY');
     }
     // reset affected rows
     $this->_affected_rows = null;
     // don't update the primary key
     unset($data[$this->_primary_col]);
     // remove non-existent table columns from the data
     foreach ($data as $key => $val) {
         if (empty($this->_table_cols[$key])) {
             unset($data[$key]);
         }
     }
     // perform the update and track affected rows
     $this->_affected_rows = $this->_sql->update($this->_table_name, $data, $where);
     // clear the cache for this model and related models
     $this->_cache->deleteAll();
     // done!
     return $this->_affected_rows;
 }