86Stang Posted May 1, 2007 Share Posted May 1, 2007 101 question here... I need to erase all data from the database before running an import. Don't ask - it's management's decision. Anyway, could someone school me in the ways to erase all data in the DB from a php file? I'm already connected to the DB, can import, etc., I just need to figure out how to flush the current data first. Quote Link to comment https://forums.phpfreaks.com/topic/49565-emptying-entire-database/ Share on other sites More sharing options...
MadTechie Posted May 1, 2007 Share Posted May 1, 2007 Depends on rights, but drop database will do it DROP {DATABASE | SCHEMA} [iF EXISTS] db_name Quote Link to comment https://forums.phpfreaks.com/topic/49565-emptying-entire-database/#findComment-242984 Share on other sites More sharing options...
86Stang Posted May 1, 2007 Author Share Posted May 1, 2007 I got a different idea but I think it'll work the same (?) mysql_query("DELETE FROM table_name") or die(mysql_error()); Seems to be working ok but time will tell. Quote Link to comment https://forums.phpfreaks.com/topic/49565-emptying-entire-database/#findComment-242993 Share on other sites More sharing options...
bubblegum.anarchy Posted May 2, 2007 Share Posted May 2, 2007 Use TRUNCATE instead so that any auto_increment values are reset. TRUNCATE tbl_name Quote Link to comment https://forums.phpfreaks.com/topic/49565-emptying-entire-database/#findComment-243087 Share on other sites More sharing options...
brownka Posted May 3, 2007 Share Posted May 3, 2007 put all the names of the tabes in an array and use truncate. im a noobie but im sure there is a way to query all the names of the tables to automate the array creation. goodluck! $tables=array("grades","inclass","submitted","posted","classes"); foreach($tables as $table) { $query = "truncate $table"; $result = mysql_query($query,$conn) or die("Query error"); Quote Link to comment https://forums.phpfreaks.com/topic/49565-emptying-entire-database/#findComment-244638 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.