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 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 use TUNCATE tablename or you can just export database structure and restore back overwriting the old database do take backup of your old database 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); } 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
Archived
This topic is now archived and is closed to further replies.