i have written a tool for backing up cpanel with windows, check http://krakjoe.info ( myCpanelBackup )
to use that php code you'd need to loop over an array of the table names for success, but nice snippet though
Right. I have written this code in one of my project. If you still want a way to backup the database with php code. Let me know.
Go to tufat.com/s_mybackup_web_database_exporter.htm is what i use as it has the facility to automatically mail backups hourly/daily/what time you set, you can also store backups on server through ftp also .