james909 Posted October 31, 2013 Share Posted October 31, 2013 Hi programmers. Could someone please explain to me how to clear all rows from a database so that the database is empty? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/283484-php-to-dropclearwipe-mysql-database-so-that-all-rows-are-deleted-and-the-database-is-empty/ Share on other sites More sharing options...
PravinS Posted November 1, 2013 Share Posted November 1, 2013 (edited) use TUNCATE tablename or you can just export database structure and restore back overwriting the old database do take backup of your old database Edited November 1, 2013 by PravinS Quote Link to comment https://forums.phpfreaks.com/topic/283484-php-to-dropclearwipe-mysql-database-so-that-all-rows-are-deleted-and-the-database-is-empty/#findComment-1456456 Share on other sites More sharing options...
Barand Posted November 1, 2013 Share Posted November 1, 2013 Something like this $db = new mysqli(HOST,USERNAME,PASSWORD,'databasename'); $sql = "SHOW TABLES"; $res = $db->query($sql); while ($row = $res->fetch_row()) { echo "$row[0]<br>"; $sql2 = "TRUNCATE TABLE `$row[0]`"; $db->query($sql2); } Quote Link to comment https://forums.phpfreaks.com/topic/283484-php-to-dropclearwipe-mysql-database-so-that-all-rows-are-deleted-and-the-database-is-empty/#findComment-1456473 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.