I have four databases which I am trying to backup in php using exec(mysqldump...)
I am using the following code,
$command = 'mysqldump --single-transaction --comments --dump-date --host='.$host[$db].' --user='.$dbuser[$db].' --password='.$dbpass[$db].' '.$dbname[$db].' | zip > '.$filepath;
exec($command, $_messages, $result);
if($result)
{
echo '<p class="success">Backup for database '.$dbname[$db].' complete. Located at: '.$filepath.'';
}
else
{
echo 'Backup for database '.$dbname[$db].' failed
';
}
The $host, $dbname, etc are same variables I use for connecting to the databases for normal access, so I know they are valid. I was under the impression that 3rd argument on the exec() function was True if successful, False otherwise. The dumps are cycled through using the $db variable, so the commands issued are identical in format, but obviously with different details for each database. The results are as follows,
- Database A dump works fine, but $result is returned as False
- Database B dump produces a file, but no contents and $result is returned as False
- Database c dump produces a file, but no contents and $result is returned as False
- Database D dump apparently works ($result True) but produces no file.
So I am beginning the think the correct interpretation of $result is 0 for success.
There is no difference if the databases are processed in a loop or processed individually. No problem in producing the dumps via phpMyAdmin and the dump for database A tallys with the phpMyAdmin dump.
I'm on a shared hosting platform running php 5.4 and MySQL 5.6.30 with cPanel.
Anyone got any thoughts as to what might be happening?
Many thanks.
Copyright License:
Author:「user3726207」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/38291561/mysqldump-dump-via-php-exec-works-for-1st-db-but-not-next-3