PHP/MySQL: is there a self-contained (simple!) script to do MySQL (entire) DB contents (and structure) backup

I've found several snippets and strategies on the web, but none that i see are complete/self-contained.

Icing on the cake would be to have the option for saving to a server-side filename, vs.  clientside (PC) local  harddisk

(p.s. i'm not concerned about compressing the data, but if that's easy too, ...)

Who is Participating?
nplibConnect With a Mentor Commented:
you can't do it solely through php.

php wil allow you to run query's, and run shell commands,

but other then that, that is the best your gonna get.

you need to run a shell command in order to dump the db.
mysqldump -u root -pPASSWORD --all-databases --opt > filename.sql
RWJDComConnect With a Mentor Commented:
I've always used phpMyAdmin ( for doing backups from the web otherwise I would go with nplib's suggestion of using the mysqldump dump command, if you need to be able to run it from the web you can always create a php script to run the mysqldump command.
   system("mysqldump -uroot -pPASSWORD dbname > file.sql");

Open in new window

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

willsherwoodAuthor Commented:
sorry i wasn't clear:  how can i do this from PHP.  I don't want to execute shell commands...

i think i'm looking for a script that loops thru all tables and dumps them...
BenMorelConnect With a Mentor Commented:
If you don't want to system() something, there is no "clean" nor "easy" way to do this, I'm afraid.
Let's resume the different possibilities :
- Use mysqldump (above solution), must be used with a system() call or equivalent.
- Use SELECT * INTO OUTFILE 'file' FROM table; but that can only write csv-like files on your system.
- Use a homebrew function that would be able to query the db, table after table, row after row, determining the column types, collations, and so on, and generating SQL queries based on that. Scripts like this probably exist, although I'm not aware of any. I guess phpmyadmin works that way.

AFAIK, there is no "built-in" function to do that.

So the solution for you would be to find such a library, and to keep it up to date, because as mysql evolves, this sofware must also evolve to be able to dump all particularities of your tables !

Sorry for not being able to help more than that :)
willsherwoodAuthor Commented:
thanks to all.
i guess that's why i wasn't able to find a script!!
it seems like this would be a basic/common function to support
Why not starting your own open source project? ;)
All Courses

From novice to tech pro — start learning today.