Dec
29
Backup Export MySQL Database Using PHP
December 29, 2007 |
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
- MySQL Default Schema
- Troubleshoot Flash PHP Can’t Upload Flv
- Cook up Web sites fast with CakePHP MySQL Syntax Problem
- PHP eval is evil
- PHP Random Password Generation
- Use Adsense for Search on WordPress
- PHP cURL XAMPP
- PHP Find Absolute Path
- PHP - Display all jpg Image Infomation
Comments
1 Comment so far



































[...] 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. [...]