Skip to content

Instantly share code, notes, and snippets.

@CurtisHumphrey
Created July 14, 2013 00:48
Show Gist options
  • Save CurtisHumphrey/5992748 to your computer and use it in GitHub Desktop.
Save CurtisHumphrey/5992748 to your computer and use it in GitHub Desktop.
codeigniter php code for truncating all tables and reset auto_increments
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