Backing up a MySQL database using PHP.
<?php // Enter Database access details $host= 'dbxx.oneandone.co.uk'; $user= 'dbxxxxxx'; $pass= 'xxxxxxxx'; $db= 'dbxxxxxxx'; $filename= getenv('DOCUMENT_ROOT').'/'.date('Y').'-'.date('M').'-'.date('D'); // Instructing the system to zip and store the database system(sprintf( 'mysqldump --opt -h%s -u%s -p%s %s | gzip > %s.sql.gz', $host, $user, $pass, $db, $filename )); echo '+DONE'; ?> |
I haven’t actually tried this one yet. The one I use is similar and works with the ‘exec’ command – so this one is a much better function.
Write a Comment
Let me know what you think?