diff options
-rw-r--r-- | system/database/DB_active_rec.php | 23 | ||||
-rw-r--r-- | user_guide/changelog.html | 1 | ||||
-rw-r--r-- | user_guide/database/active_record.html | 18 |
3 files changed, 30 insertions, 12 deletions
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index dfa0a3efb..d48d1c5bd 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -925,11 +925,13 @@ class CI_DB_active_record extends CI_DB_driver { * Compiles a delete string and runs the query
*
* @access public
- * @param string the table to retrieve the results from
+ * @param mixed the table(s) to delete from. String or array
* @param mixed the where clause
+ * @param mixed the limit clause
+ * @param boolean
* @return object
*/
- function delete($table = '', $where = '', $limit = NULL)
+ function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE)
{
if ($table == '')
{
@@ -945,6 +947,16 @@ class CI_DB_active_record extends CI_DB_driver { $table = $this->ar_from[0];
}
+ if (is_array($table))
+ {
+ foreach($table as $single_table)
+ {
+ $this->delete($this->dbprefix.$single_table, $where, $limit, FALSE);
+ }
+ $this->_reset_write();
+ return;
+ }
+
if ($where != '')
{
$this->where($where);
@@ -963,10 +975,13 @@ class CI_DB_active_record extends CI_DB_driver { }
return FALSE;
}
-
+
$sql = $this->_delete($this->dbprefix.$table, $this->ar_where, $this->ar_limit);
- $this->_reset_write();
+ if ($reset_data)
+ {
+ $this->_reset_write();
+ }
return $this->query($sql);
}
diff --git a/user_guide/changelog.html b/user_guide/changelog.html index 033824b56..3fbac474a 100644 --- a/user_guide/changelog.html +++ b/user_guide/changelog.html @@ -70,6 +70,7 @@ Change Log <li>Added 'random' as an <kbd>order_by()</kbd> option in <a href="./database/active_record.html">Active Record</a>.</li>
<li>Added <kbd>where_in()</kbd>, <kbd>where_in_or()</kbd>, <kbd>where_not_in()</kbd>, and <kbd>where_not_in_or()</kbd> to <a href="./database/active_record.html">Active Record</a>.</li>
<li>Added support for <kbd>limit()</kbd> into <kbd>update()</kbd> and <kbd>delete()</kbd> statements in <a href="./database/active_record.html">Active Record</a>.</li>
+ <li>Added the ability to pass an array of tables to the <kbd>delete()</kbd> statement in <a href="./database/active_record.html">Active Record</a>.</li>
<li>Added titles to all user manual pages.</li>
<li>Added a check for NULL fields in the MySQL database backup utility.</li>
<li>Documented the <kbd>timezones()</kbd> function in the <a href="./helpers/date_helper.html">Date Helper</a>.</li>
diff --git a/user_guide/database/active_record.html b/user_guide/database/active_record.html index d938b5dff..e7c823fde 100644 --- a/user_guide/database/active_record.html +++ b/user_guide/database/active_record.html @@ -623,14 +623,16 @@ $this->db->delete('mytable', array('id' => $id)); <p>The first parameter is the table name, the second is the where clause. You can also use the <dfn>where()</dfn> or <dfn>or_where()</dfn> functions instead of passing
the data to the second parameter of the function:</p>
-<code>
-$this->db->where('id', $id);<br />
-$this->db->delete('mytable');
-<br /><br />
-// Produces:<br />
-// DELETE FROM mytable <br />
-// WHERE id = $id</code>
-
+<p><code> $this->db->where('id', $id);<br />
+ $this->db->delete('mytable'); <br />
+ <br />
+ // Produces:<br />
+ // DELETE FROM mytable <br />
+ // WHERE id = $id</code></p>
+<p>An array of table names can be passed into delete() if you would like to delete data from more then 1 table.</p>
+<p><code>$tables = array('table1', 'table2', 'table3');<br />
+$this->db->where('id', '5');<br />
+$this->db->delete($tables);</code></p>
<p class="important"><strong>Note:</strong> All values are escaped automatically producing safer queries.</p>
|