Welcome Guest, Not a member yet? Register   Sign In
How to use $this->db->empty_table() for many tables?
#1

[eluser]shinokada[/eluser]
I have 20 tables to empty.

When I use it following the first one does not work. And the second method only empties the first table.

What is the best way to empty many tables?
Do I have empty one by one?

Thanks in advance.

Code:
// first
$tables = array('table1','table2',....)
$this->db->empty_table($tables);    

// second
$this->db->empty_table('table1','table2',....);
#2

[eluser]troy_mccormick[/eluser]
The manual only shows being able to pass in one table name at a time. Your best bet would be to loop through each table in that array like such:

Code:
<?php
$tables = array('table1','table2') ;
foreach($tables AS $table) {
     $this->db->empty_table($table);
     echo "$table emptied<br />";
}
?&gt;

From the manual:
Quote:$this->db->empty_table();

Generates a delete SQL string and runs the query.

Code:
&lt;?php
$this->db->empty_table('mytable');
?&gt;
// Produces
// DELETE FROM mytable

EDIT:
Wouldn't it be better to run $this->db->truncate(); instead? I'm not sure...
#3

[eluser]danmontgomery[/eluser]
Code:
$tables = array ('table1','table2',...);
foreach($tables as $_table) { $this->db->empty_table($_table); }




Theme © iAndrew 2016 - Forum software by © MyBB