Dec

29


For people who don’t have phpMyAdmin or MySQL Administrator. There is a quick and easy way to backup mysql database using PHP from browser. Below is the code, follow the command you will know how to customize and make it work in your case. Enjoy!

<?php
// Enter your MySQL access data
$host= 'MySQL host';
$user= 'database username';
$pass= 'database password';
$db=   'database name';
// Enter the directory the sql file will be created at.
// For example, if you have a web site www.example.com,
// and you want the sql file to be generated at
// www.example.com/backups, then $backupdir = 'backups';
$backupdir = 'backups';
// Compute the time the sql file's generated.
$today = getdate();
$day = $today[mday];
if ($day < 10) {
$day = "0$day";
}
$month = $today[mon];
if ($month < 10) {
$month = "0$month";
}
$year = $today[year];
$hour = $today[hours];
$min = $today[minutes];
$sec = "00";
// Execute mysqldump command.
// It will produce a file named $db-$year$month$day-$hour$min.gz
// under $DOCUMENT_ROOT/$backupdir
system(sprintf(
'mysqldump --opt -h %s -u %s -p%s %s | gzip > %s/%s/%s-%s%s%s-%s%s.gz',
$host,
$user,
$pass,
$db,
getenv('DOCUMENT_ROOT'),
$backupdir,
$db,
$year,
$month,
$day,
$hour,
$min
));
echo '+DONE';
?>


Similar Posts

Comments

Name (required)

Email (required)

Website

Speak your mind

1 Comment so far

  1. My Web Hosting Site » Blog Archive » Backup Export MySQL Database Using PHP on December 31, 2007 3:02 am

    [...] Internet and Businesses Online: Web Hosting Articl article is brought to you using rss feeds.Here is some of the latest breaking Casey Aldridge news. [...]

Sponsors




Links