For example ...
{{code: php
$sql = Solar::factory('Solar_Sql');
$table = 'events';
$where = $sql->quoteInto('status = ?', 'cancelled');
$rows_affected = $sql->delete($table, $where);
calls 'DELETE FROM events WHERE status = "cancelled"'
}}
For the $where parameter, you can also pass multiple WHERE conditions as
an array to be "AND"ed together.
{{code: php
$sql = Solar::factory('Solar_Sql');
$table = 'events';
$where = array(
"date >= ?" => '2006-01-01',
"date <= ?" => '2006-01-31',
"status = ?" => 'cancelled',
);
$rows_affected = $sql->delete($table, $where);
calls:
DELETE FROM events WHERE date >= "2006-01-01"
AND date <= "2006-01-31" AND status = "cancelled"
}}
/** * * Removes old session data (garbage collection). * * @param int $lifetime Removes session data not updated since this many * seconds ago. E.g., a lifetime of 86400 removes all session data not * updated in the past 24 hours. * * @return bool * */ public function gc($lifetime) { // timestamp is current time minus session.gc_maxlifetime $timestamp = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s') - $lifetime)); // delete all sessions last updated before the timestamp $this->_sql->delete($this->_config['table'], array("{$this->_config['updated_col']} < ?" => $timestamp)); return true; }
/** * * Deletes rows from the model table and deletes cache entries. * * @param string|array $where The WHERE clause to identify which rows to * delete. * * @return int The number of rows affected. * * @see Solar_Sql_Model_Cache::deleteAll() * */ public function delete($where) { // perform the deletion and track affected rows $this->_affected_rows = $this->_sql->delete($this->_table_name, $where); // clear the cache for this model and related models $this->_cache->deleteAll(); // done! return $this->_affected_rows; }