Skip to content

Instantly share code, notes, and snippets.

@stephen304
Created July 4, 2014 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephen304/f09fe7d0e08abbb2d820 to your computer and use it in GitHub Desktop.
Save stephen304/f09fe7d0e08abbb2d820 to your computer and use it in GitHub Desktop.
Truncate all tables PHP
<?php
$connection = new mysqli($host, $user, $pass, $db);
$sql = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA LIKE '".$db."'";
$result = $connection->query($sql);
$tables = $result->fetch_all(MYSQLI_ASSOC);
foreach($tables as $table)
{
$sql = "TRUNCATE TABLE `".$table['TABLE_NAME']."`";
$result = $connection->query($sql);
}
?>
@khalidJA
Copy link

Big Like

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment