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. 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 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. 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 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"); Link to comment https://forums.phpfreaks.com/topic/49565-emptying-entire-database/#findComment-244638 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.