tsilenzio Posted July 24, 2007 Share Posted July 24, 2007 Ok on my site for some reason if i dont emtpy a database then when i drop it and recreate it, it will have all the entrys still in it. So i was wondering if somone could help me determine some kind of script that will figure out how many tables there are, then emtpy them, after that drop the tables or is this impossible? - deathseaker Thanx in advance! Link to comment https://forums.phpfreaks.com/topic/61573-php-droping-emtpying-unknown-tables/ Share on other sites More sharing options...
tsilenzio Posted July 24, 2007 Author Share Posted July 24, 2007 *Bump* Link to comment https://forums.phpfreaks.com/topic/61573-php-droping-emtpying-unknown-tables/#findComment-306471 Share on other sites More sharing options...
tsilenzio Posted July 24, 2007 Author Share Posted July 24, 2007 well here is the verzion i came up with... <?php require_once('config.php'); $result = mysql_list_tables($db_database); if (!$result) { print "DB Error, could not list tables\n"; print 'MySQL Error: ' . mysql_error(); exit; } while ($row = mysql_fetch_row($result)) { $table = row[0]; $query = "TRUNCATE TABLE '$table'"; processQuery($query); $query = "DROP TABLE '$table'"; processQuery($query); } ?> processQuery connects to the database and does all that stuff for me.. Link to comment https://forums.phpfreaks.com/topic/61573-php-droping-emtpying-unknown-tables/#findComment-306517 Share on other sites More sharing options...
cooldude832 Posted July 24, 2007 Share Posted July 24, 2007 why? you can dump the whole database off a single line (or delete it) instead of dumping all the data also why truncate and then dump just dump also its more standard to do $result = mysql_list_tables($db_database) or die(mysql_error()); saves you code and same result Link to comment https://forums.phpfreaks.com/topic/61573-php-droping-emtpying-unknown-tables/#findComment-306520 Share on other sites More sharing options...
tsilenzio Posted July 24, 2007 Author Share Posted July 24, 2007 i explaiend on first post because the database i use on the site will READD the data once i drop the table and if i create it down the line it will READD whatever data was inside it for some reason =/ Link to comment https://forums.phpfreaks.com/topic/61573-php-droping-emtpying-unknown-tables/#findComment-306523 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.