How do I run a 'save as' script to export database?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

How do I run a 'save as' script to export database?

Post by simonmlewis »

We have backups of our websites, but I would like to be able to click a button in our own CMS that saves either some fundamental tables, or ALL tables. So it basically does what the phpmyadmin 'export' to .sql does.

How does one go about that?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How do I run a 'save as' script to export database?

Post by Celauran »

You can't stick with mysqldump at the command line? Or a manual export when you need one?

Code: Select all

So it basically does what the phpmyadmin 'export' to .sql does.
phpMyAdmin is written in PHP. Have you taken a look at how they do it?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I run a 'save as' script to export database?

Post by simonmlewis »

I can login to the control panel system, and go thru the various buttons to get there - but we regularly work in the CMS for the website so I wondered if I could do it from there instead.

I don't quite know where in phpmyadmin that code would be. But I figured there would be an easy way to do it anyway.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How do I run a 'save as' script to export database?

Post by Celauran »

You basically need the schema definitions, SELECT * from each table, and write to file. What have you tried so far?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I run a 'save as' script to export database?

Post by simonmlewis »

I Tried this simple query:

Code: Select all

<?php
include "dbconn.php"; 
mysql_query("SELECT * FROM products INTO OUTFILE '/tmp/products.sql'");
echo "yes";
?>
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply