Created
July 14, 2013 00:48
-
-
Save CurtisHumphrey/5992748 to your computer and use it in GitHub Desktop.
codeigniter php code for truncating all tables and reset auto_increments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function empty_all() | |
{ | |
$query = $this->db->query("SHOW TABLES"); | |
$name = $this->db->database; | |
foreach ($query->result_array() as $row) | |
{ | |
$table = $row['Tables_in_' . $name]; | |
$this->db->query("TRUNCATE " . $table); | |
$this->db->query("ALTER TABLE ".$table." AUTO_INCREMENT = 1"); | |
} | |
$this->output->set_output("Database emptyed"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment