Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > Putting it Together > Databases

Reply
 
LinkBack Thread Tools
Old 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 geyids is on a distinguished road
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
__________________
www.whereis.co.ke is the place to be
geyids is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old January 17th, 2008, 01:21 PM   #2
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
Re: how to delete tables with a prefix

Try:
Code:
DROP TABLE php_
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old 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 geyids is on a distinguished road
Re: how to delete tables with a prefix

will that delete all the tables including like this php_zebra
__________________
www.whereis.co.ke is the place to be
geyids is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old January 17th, 2008, 01:31 PM   #4
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
Re: how to delete tables with a prefix

That was wrong actually.
I think this should work but I'm not entirely sure.
Code:
DROP TABLE php_*
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old 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 geyids is on a distinguished road
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
__________________
www.whereis.co.ke is the place to be
geyids is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old January 17th, 2008, 02:18 PM   #6
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
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$i0); 
 if (
substr($tablename03) == "php"
 { 
 if (
mysql_query("drop TABLE ".$tablename)) print "droped ".tablename."!<br />"
 } 

?>
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old 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 geyids is on a distinguished road
Re: how to delete tables with a prefix

lemmi try it out
__________________
www.whereis.co.ke is the place to be
geyids is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old 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 geyids is on a distinguished road
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
__________________
www.whereis.co.ke is the place to be
geyids is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old January 17th, 2008, 03:25 PM   #9
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
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()); 
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old 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 geyids is on a distinguished road
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); 
__________________
www.whereis.co.ke is the place to be
geyids is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old January 17th, 2008, 04:01 PM   #11
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
Re: how to delete tables with a prefix

Did you try the code I posted?
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old 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 geyids is on a distinguished road
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$i0); 
     if (
substr($tablename03) == "phpbb_"
     { 
     if (
mysql_query("drop TABLE ".$tablename)) print "droped ".tablename."!<br />"
     } 
    } 
    
?>
__________________
www.whereis.co.ke is the place to be
geyids is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old January 17th, 2008, 04:57 PM   #13
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
Re: how to delete tables with a prefix

You're not getting any error?
Remove the @ before the mysql_connect.
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old 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 geyids is on a distinguished road
Re: how to delete tables with a prefix

no error at all. i have removed the @ and still thesame. a blank page
__________________
www.whereis.co.ke is the place to be
geyids is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old January 18th, 2008, 02:17 AM   #15
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
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.
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old 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 geyids is on a distinguished road
Re: how to delete tables with a prefix

still no output. just let it go i will work with phpMyAdmin
__________________
www.whereis.co.ke is the place to be
geyids is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
delete by checkbox FlashO Classic ASP 3 March 30th, 2008 04:42 AM


Search Engine Optimization by vBSEO 3.2.0 RC8