Create dump DB using PHP

08-20 12:25
  1. PHP
  2. code
  3. database
Short instructions ​ for creating a database dump using php.

Export database using MySQLDump already described, repeat the command:


mysqldump -uYourLogin -pYourPassword DBName > fileDBName.sql
Then wrap this command to PHP, open necessary php file and add code to it:


exec('mysqldump -uYourLogin -pYourPassword DBName > /path/to/save/fileDBName.sql');
If you need to store a few versions of dump base, then you can specify lead  time of dump in filename:


exec('mysqldump -uYourLogin -pYourPassword DBName > /path/to/save/fileDBName-' . date('d.m.Y-H:i:s') . '.sql');
 You can choose time format at its discretion. Then you can add this file to tasks crone and get automatic dump of base, if you need.
Translate article source
Want to get a great job? Add CV