mysqldump dump via php exec works for 1st db but not next 3

2016-07-10T19:51:13

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

About “mysqldump dump via php exec works for 1st db but not next 3” questions

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[$...
See bottom for solution I'm running mysqldump as part of a php script called via cron job. Is it possible to return stderr from the mysqldump command, maybe assign it to a variable that can be read
I am trying to create a mysql database dump in a php class. I am executing the following code but only an empty dump file will create. But the same command works fine when I execute it in the comm...
I'm working on a project and I'm playing around with the maintenance ability to dump and restore a database to work with early git development. My database will be changing a lot so I need a simple...
I am trying to take mysqldump of database through php, i am able to take database dump through command line this way only. d: cd "d:\wamp\bin\mysql\mysql5.5.24\bin" mysqldump.exe mysqldump --user=...
This is working: exec('mysqldump --single-transaction --user=myusername --password=mypassword --host=localhost mydb &gt; /home/path/public_html/a.sql'); exec('mysql --user=myusername --password=
I want to use mysqldump from my php script using exec() function. I did that in php $com = "mysqldump --user=username --password=mypassword mydatabasename &gt;c:\dump\test.sql"; $exec($com,$resul...
I'm trying run exec with mysqldump in my PHP file. It doesn't work, I'm even trying to use it without variables like this: exec('mysqldump --user=xx --password=xx --host=xx db settings &gt; /output/
I have a PHP script which is executed as such: exec(&quot;php myscript.php &gt; /dev/null &amp;&quot;); Within myscript.php I attempt to dump the database as follows for backup: exec(&quot;mysqldu...
I am trying to create periodic backups (poor man's cron) of my database using mysqldump with exec() function. I am using XAMPP/PHP7 on macOS. $command = "$mysqldump_location -u$db_user -h$db_host -p$

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.