| Welcome to Webforumz.com. |
|
Jan 17th, 2008, 17:08
|
#1 (permalink)
|
|
Reputable Member
Join Date: Mar 2007
Location: Tanzania
Age: 19
Posts: 209
|
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
__________________
with great power comes with great responsibility :kicking: | this is me
|
|
|
Jan 17th, 2008, 17:21
|
#2 (permalink)
|
|
Administrator
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 4,102
|
Re: how to delete tables with a prefix
Try:
- Code: Select all
DROP TABLE php_
__________________
Languages: PHP, mySQL (queries), C#, (X)html, CSS, JS.
|
|
|
Jan 17th, 2008, 17:29
|
#3 (permalink)
|
|
Reputable Member
Join Date: Mar 2007
Location: Tanzania
Age: 19
Posts: 209
|
Re: how to delete tables with a prefix
will that delete all the tables including like this php_zebra
__________________
with great power comes with great responsibility :kicking: | this is me
|
|
|
Jan 17th, 2008, 17:31
|
#4 (permalink)
|
|
Administrator
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 4,102
|
Re: how to delete tables with a prefix
That was wrong actually.
I think this should work but I'm not entirely sure.
- Code: Select all
DROP TABLE php_*
__________________
Languages: PHP, mySQL (queries), C#, (X)html, CSS, JS.
|
|
|
Jan 17th, 2008, 17:32
|
#5 (permalink)
|
|
Reputable Member
Join Date: Mar 2007
Location: Tanzania
Age: 19
Posts: 209
|
Re: how to delete tables with a prefix
- Code: Select all
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
__________________
with great power comes with great responsibility :kicking: | this is me
|
|
|
Jan 17th, 2008, 18:18
|
#6 (permalink)
|
|
Administrator
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 4,102
|
Re: how to delete tables with a prefix
This php should work, found it on a forum.
- PHP: Select all
<?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 />"; } } ?>
__________________
Languages: PHP, mySQL (queries), C#, (X)html, CSS, JS.
|
|
|
Jan 17th, 2008, 18:49
|
#7 (permalink)
|
|
Reputable Member
Join Date: Mar 2007
Location: Tanzania
Age: 19
Posts: 209
|
Re: how to delete tables with a prefix
lemmi try it out
__________________
with great power comes with great responsibility :kicking: | this is me
|
|
|
Jan 17th, 2008, 19:24
|
#8 (permalink)
|
|
Reputable Member
Join Date: Mar 2007
Location: Tanzania
Age: 19
Posts: 209
|
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
__________________
with great power comes with great responsibility :kicking: | this is me
|
|
|
Jan 17th, 2008, 19:25
|
#9 (permalink)
|
|
Administrator
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 4,102
|
Re: how to delete tables with a prefix
You have put in your connection string yeah?
Try replacing
:
- PHP: Select all
$result = mysql_query("SHOW tables");
with:
- PHP: Select all
$result = mysql_query("SHOW tables") or die(mysql_error());
__________________
Languages: PHP, mySQL (queries), C#, (X)html, CSS, JS.
|
|
|
Jan 17th, 2008, 19:50
|
#10 (permalink)
|
|
Reputable Member
Join Date: Mar 2007
Location: Tanzania
Age: 19
Posts: 209
|
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
- PHP: Select all
$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);
__________________
with great power comes with great responsibility :kicking: | this is me
|
|
|
Jan 17th, 2008, 20:01
|
#11 (permalink)
|
|
Administrator
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 4,102
|
Re: how to delete tables with a prefix
Did you try the code I posted?
__________________
Languages: PHP, mySQL (queries), C#, (X)html, CSS, JS.
|
|
|
Jan 17th, 2008, 20:09
|
#12 (permalink)
|
|
Reputable Member
Join Date: Mar 2007
Location: Tanzania
Age: 19
Posts: 209
|
Re: how to delete tables with a prefix
yes the whole thing looks like this now
- PHP: Select all
<?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 />"; } } ?>
__________________
with great power comes with great responsibility :kicking: | this is me
|
|
|
Jan 17th, 2008, 20:57
|
#13 (permalink)
|
|
Administrator
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 4,102
|
Re: how to delete tables with a prefix
You're not getting any error?
Remove the @ before the mysql_connect.
__________________
Languages: PHP, mySQL (queries), C#, (X)html, CSS, JS.
|
|
|
Jan 18th, 2008, 06:09
|
#14 (permalink)
|
|
Reputable Member
Join Date: Mar 2007
Location: Tanzania
Age: 19
Posts: 209
|
Re: how to delete tables with a prefix
no error at all. i have removed the @ and still thesame. a blank page
__________________
with great power comes with great responsibility :kicking: | this is me
|
|
|
Jan 18th, 2008, 06:17
|
#15 (permalink)
|
|
Administrator
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 4,102
|
Re: how to delete tables with a prefix
Try changing:
- PHP: Select all
$connection = @mysql_connect($db_host, $db_user, $db_password) or die("error connecting"); mysql_select_db($db_name, $connection);
to:
- PHP: Select all
mysql_connect($db_host, $db_user, $db_password) or die("error connecting"); mysql_select_db($db_name);
Otherwise I dont know.
__________________
Languages: PHP, mySQL (queries), C#, (X)html, CSS, JS.
|
|
|
Jan 19th, 2008, 19:23
|
#16 (permalink)
|
|
Reputable Member
Join Date: Mar 2007
Location: Tanzania
Age: 19
Posts: 209
|
Re: how to delete tables with a prefix
| | | |