Search code examples
phpmysqlpassthru

mysqldump passthru returncode's


I am trying to do a mysql dump via php.

This is the code

$backupFile = $table. "-". date("Y-m-d-H:i:s") . '.gz';
    //Command nog aanpassen....
    $command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname  | gzip > $backupFile";
    //$status = system($command);
    echo $backupFile ."<br>";
    $status = passthru($command, $a);
    echo "output:" .  $a;

The value of $a = 2. But I can't find what it means. I also can't find the backup file anywhere.

Any idea's?


Solution

  • I'm not sure if this is the problem, but it looks like your password passing parameter is incorrect.

    If you use -p you need to have the password right next to it, without whitespace, like so:

    $command = "mysqldump --opt -h $dbhost -u $dbuser -p$dbpass $dbname  | gzip > $backupFile";
    

    Or use the long --password=$dbpass.

    For example:

    $command = "mysqldump --opt -h $dbhost -u $dbuser --password=$dbpass $dbname  | gzip > $backupFile";
    

    From the mysqldump man page:

    --password[=password], -p[password]

    The password to use when connecting to the server. If you use the short option form (-p), you cannot have a space between the option and the password. If you omit the password value following the --password or -p option on the command line, you are prompted for one.