Back Up Your MySQL Database with PHP

Obviously the ideal way to back up a MySQL database is to use mysqldump. Failing that, a lot of people will use PHPMyAdmin. Unfortunately, however, not everyone has command-line access to a server; and even fewer are able to execute mysqldump from a script. If PHPMyAdmin isn’t already installed, it can be difficult to get it installed and configured on a shared hosting account. Therefore, it’s sometimes necessary to use a PHP script to back up a MySQL database.

David Walsh has done a nice job of putting together a PHP script to backup your MySQL databases. Below is a copy of the code he provides in his blog article:

Back Up A Large MySQL Database

Anyone that’s dealt with a Web application using a MySQL backend has probably dealt with incomplete backups. Those of you that use phpBB have almost certainly encountered this issue. Unfortunately, within phpBB and quite a few other PHP/MySQL-based applications, the backup scripts fail miserably with any reasonably large amount of data. Most of them fail because of either PHP time outs or file size limits. This article will show you two different ways to successfully back up that data. At least one of these two methods should be available in almost every remote hosting package that uses MySQL and PHP.