|
|
 |
January 17th, 2008, 01:08 PM
|
#1
|
|
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 21
Posts: 231
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
how to delete tables with a prefix
How do I delete tables with a certain prefix eg that starts with php_ all at once. Thanks
|
|
|
January 17th, 2008, 01:21 PM
|
#2
|
|
Elite Veteran
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Thanks: 2
Thanked 3 Times in 3 Posts
|
Re: how to delete tables with a prefix
|
|
|
January 17th, 2008, 01:29 PM
|
#3
|
|
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 21
Posts: 231
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Re: how to delete tables with a prefix
will that delete all the tables including like this php_zebra
|
|
|
January 17th, 2008, 01:31 PM
|
#4
|
|
Elite Veteran
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Thanks: 2
Thanked 3 Times in 3 Posts
|
Re: how to delete tables with a prefix
That was wrong actually.
I think this should work but I'm not entirely sure.
|
|
|
January 17th, 2008, 01:32 PM
|
#5
|
|
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 21
Posts: 231
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Re: how to delete tables with a prefix
Code:
mysql> drop table phpbb_*
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '*' at
line 1
|
|
|
January 17th, 2008, 02:18 PM
|
#6
|
|
Elite Veteran
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Thanks: 2
Thanked 3 Times in 3 Posts
|
Re: how to delete tables with a prefix
This php should work, found it on a forum.
Code:
<?php //assuming you're connected and have selected the db already $result = mysql_query("SHOW tables"); for ($i = 0; $i < mysql_num_rows($result); $i++) { $tablename = mysql_result($result, $i, 0); if (substr($tablename, 0, 3) == "php") { if (mysql_query("drop TABLE ".$tablename)) print "droped ".tablename."!<br />"; } } ?>
|
|
|
January 17th, 2008, 02:49 PM
|
#7
|
|
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 21
Posts: 231
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Re: how to delete tables with a prefix
lemmi try it out
|
|
|
January 17th, 2008, 03:24 PM
|
#8
|
|
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 21
Posts: 231
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Re: how to delete tables with a prefix
nothing happens the page is just blank doesn't echo the result droped so nothing has happend and the tables are still there
|
|
|
January 17th, 2008, 03:25 PM
|
#9
|
|
Elite Veteran
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Thanks: 2
Thanked 3 Times in 3 Posts
|
Re: how to delete tables with a prefix
You have put in your connection string yeah?
Try replacing
:
Code:
$result = mysql_query("SHOW tables");
with:
Code:
$result = mysql_query("SHOW tables") or die(mysql_error());
|
|
|
January 17th, 2008, 03:50 PM
|
#10
|
|
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 21
Posts: 231
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Re: how to delete tables with a prefix
This is how i connected to my database. Is it right? I still get a blank page
Code:
$db_host = "localhost"; $db_user = "my_user"; $db_password = "my_passwd"; $db_name = "my_name"; $connection = @mysql_connect($db_host, $db_user, $db_password) or die("error connecting"); mysql_select_db($db_name, $connection);
|
|
|
January 17th, 2008, 04:01 PM
|
#11
|
|
Elite Veteran
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Thanks: 2
Thanked 3 Times in 3 Posts
|
Re: how to delete tables with a prefix
Did you try the code I posted?
|
|
|
January 17th, 2008, 04:09 PM
|
#12
|
|
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 21
Posts: 231
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Re: how to delete tables with a prefix
yes the whole thing looks like this now
Code:
<?php $db_host = "localhost"; $db_user = "my_user"; $db_password = "my_passwd"; $db_name = "my_name"; $connection = @mysql_connect($db_host, $db_user, $db_password) or die("error connecting"); mysql_select_db($db_name, $connection); //assuming you're connected and have selected the db already $result = mysql_query("SHOW tables") or die(mysql_error()); for ($i = 0; $i < mysql_num_rows($result); $i++) { $tablename = mysql_result($result, $i, 0); if (substr($tablename, 0, 3) == "phpbb_") { if (mysql_query("drop TABLE ".$tablename)) print "droped ".tablename."!<br />"; } } ?>
|
|
|
January 17th, 2008, 04:57 PM
|
#13
|
|
Elite Veteran
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Thanks: 2
Thanked 3 Times in 3 Posts
|
Re: how to delete tables with a prefix
You're not getting any error?
Remove the @ before the mysql_connect.
|
|
|
January 18th, 2008, 02:09 AM
|
#14
|
|
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 21
Posts: 231
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Re: how to delete tables with a prefix
no error at all. i have removed the @ and still thesame. a blank page
|
|
|
January 18th, 2008, 02:17 AM
|
#15
|
|
Elite Veteran
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Thanks: 2
Thanked 3 Times in 3 Posts
|
Re: how to delete tables with a prefix
Try changing:
Code:
$connection = @mysql_connect($db_host, $db_user, $db_password) or die("error connecting"); mysql_select_db($db_name, $connection);
to:
Code:
mysql_connect($db_host, $db_user, $db_password) or die("error connecting"); mysql_select_db($db_name);
Otherwise I dont know.
|
|
|
January 19th, 2008, 03:23 PM
|
#16
|
|
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 21
Posts: 231
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Re: how to delete tables with a prefix
still no output. just let it go i will work with phpMyAdmin
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
|
delete by checkbox
|
FlashO |
Classic ASP |
3 |
March 30th, 2008 04:42 AM |
|