How to export mysql database to text file?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hoanghuy
Forum Newbie
Posts: 2
Joined: Sun Jan 16, 2005 11:11 pm

How to export mysql database to text file?

Post by hoanghuy »

i want export mysql database to text file,
please help me.

Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

phpMyAdmin is a very good tool that supports this in many formats.

What format do you want to export the database to? SQL, CSV, Tabbed, something else?
hoanghuy
Forum Newbie
Posts: 2
Joined: Sun Jan 16, 2005 11:11 pm

Post by hoanghuy »

feyd wrote:phpMyAdmin is a very good tool that supports this in many formats.

What format do you want to export the database to? SQL, CSV, Tabbed, something else?
I want back up automatically and user can't use phpMyAdmin
I want to write it by code.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

there's a facility in MySQL itself to export the data of a table: http://dev.mysql.com/doc/mysql/en/SELECT.html read the SELECT ... INTO OUTFILE parts.

You may have access to exec() and so could run: http://dev.mysql.com/doc/mysql/en/mysqldump.html

The manual way is slightly more complex, in that you have to get the table's structure, and re-engineer the query to create it.. then fetch all the rows and create insert queries for each of those as well.

We've talked about getting the table structure a little bit, recently: viewtopic.php?t=29183
Post Reply