TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Display Modes
Old 03-02-2008, 01:28 AM   #1 (permalink)
The Acquainted
 
obolus's Avatar
 
Join Date: Oct 2007
Location: florida
Posts: 110
Thanks: 36
obolus is on a distinguished road
Default Empty a DB?

Is there a way to empty a DB without having direct access (ie phpMyAdmin)? I searched the MySQL reference documentation and couldn't find (or maybe I missed it?) what I was looking for.
obolus is offline  
Reply With Quote
Old 03-02-2008, 01:35 AM   #2 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

The best method, IMHO, is to use TRUNCATE (similar to DELETE on all records, but resets the table as well).

I don't know what you mean by 'direct access'. If you don't have 'direct access' one way or another (PHP script, phpMyAdmin, mysql command line client) then how else would you perform a query?
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
The Following User Says Thank You to SOCK For This Useful Post:
obolus (03-02-2008)
Old 03-02-2008, 01:50 AM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 1,547
Thanks: 72
Wildhoney is on a distinguished road
Default

I think he means via a query and not the MySQL application via command line. If I'm right then SOCK is right with TRUNCATE !
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 03-02-2008, 02:33 AM   #4 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

Ok, well as long as the connecting user has DELETE permissions, TRUNCATE will work from a PHP script.

MySQL Manual : TRUNCATE
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
The Following User Says Thank You to SOCK For This Useful Post:
obolus (03-02-2008)
Old 03-02-2008, 09:06 PM   #5 (permalink)
The Acquainted
 
obolus's Avatar
 
Join Date: Oct 2007
Location: florida
Posts: 110
Thanks: 36
obolus is on a distinguished road
Default

I don't want to empty all of the existing tables, I want to get rid of every existing table in the database.

Thanks for replies.
obolus is offline  
Reply With Quote
Old 03-02-2008, 09:25 PM   #6 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 482
Thanks: 51
Alan @ CIT is on a distinguished road
Default

How many tables do you have? You could just use DROP TABLE (MySQL :: MySQL 5.1 Reference Manual :: 12.1.16 DROP TABLE Syntax) on each one.

PHP Code:
mysql_query("DROP TABLE foo");
mysql_query("DROP TABLE bar");
// ... 
Might take a while if you have thousands of tables though

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
The Following User Says Thank You to Alan @ CIT For This Useful Post:
obolus (03-02-2008)
Old 03-02-2008, 10:28 PM   #7 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

Quote:
Originally Posted by obolus View Post
Is there a way to empty a DB...
Quote:
Originally Posted by obolus View Post
I don't want to empty all of the existing tables, I want to get rid of every existing table in the database.
Most of the time when forum posts request info on "how to do this with a database", they're referring to the table, not the actual database. I naturally assumed you wanted to empty the table, not DROP all tables from the database.

You can use the command line tool 'mysqladmin' to drop all tables in a comma delimited list, I believe. If you could create a system exec() statement that called this function with those parameters it might be easier to do that several calls to mysql_query() to drop the table(s) (depending on how many you have).

The other way to look at it, if you have the privilege to do so, just make one call to
Code:
 DROP DATABASE databasename;
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
The Following User Says Thank You to SOCK For This Useful Post:
obolus (03-02-2008)
Old 03-02-2008, 11:26 PM   #8 (permalink)
The Acquainted
 
obolus's Avatar
 
Join Date: Oct 2007
Location: florida
Posts: 110
Thanks: 36
obolus is on a distinguished road
Default

aye, sorry for the confusion, sock. I'm pretty sure I dont have the perms to be able to drop/delete an entire database.

Alan- that answers my question to a degree, but- the problem, and my fault for not bringing this up in my original post, is that I don't know all of the table names/prefixes in the db.

So, is it possible to drop all tables in the DB with something along the lines of this:

Quote:
DROP * FROM dbname
or

Quote:
DROP TABLE * FROM dbname
..?

Thanks for help so far!
obolus is offline  
Reply With Quote
Old 03-02-2008, 11:32 PM   #9 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 701
Thanks: 2
Salathe is on a distinguished road
Default

Just DROP the database. If you don't have permissions, get them.
__________________
Salathe is offline  
Reply With Quote
Reply



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

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

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


All times are GMT. The time now is 07:55 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0