Hello,

Recently I am trying to make a php file than when it is opened it should backup
a database and promt the user to save the .sql file...

This is a feaure that has phpmyadmin but I want something very simple, just clicking
http://mywebsite.com/backup.php and the file should be avaible to download.

Could somenone help me?!

To backup a database you use mysqldump command on the db server. You must provide a root password (or dbuser password with appropriate access rights), :

mysqldump -u root -pdyourassword yourdbname > yourdbname_backup.sql

To do it from a php script use the system command:

$result = system('mysqldump -u root -pdyourassword yourdbname > somepath/yourdbname_backup.sql');
if(!result) {
    echo 'Something went wrong when trying to backup the db!';
}

Make sure the user that the web server runs under, has appropriate write access rights for the path where the backup is going to be writen to.

To enable users to download the file, provide the link to the backed up file (make sure that the file is in the publicly accessible folder).

You can also compress the file i.e. using gzip.

Also have a look at this post, too:

http://forums.devshed.com/php-development-5/php-script-download-mysql-dump-315780.html

Thank you for your help :)

You are welcome :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.