i found some simple code for dumping mysql database but whatever i do (change path to mysqldump, change arguments, change functions) it generates 0 bytes file every time! why is this happening? how could i debug my code?

$user="*********";
$password="*****";
$database="*********";

$dumpCommand='/usr/bin/mysqldump';
    $dumpCommand.=" -e -f -u$user -p	$password";    // -f to force dump even if errors
    $dumpCommand.=" $database";
	$dumpCommand.=" > bekap.sql";

$results=$dumpCommand;
exec($dumpCommand);
echo "result: ".$results;

    Echo out the $dumpCommand (wait - you never actually echo the results, so it loos like you've already done this), get to a command line, and paste the outputted command. Does it work, or do you see errors?

      Run the command on the command line from your shell. If it doesn't work there, you'll see the error output.

      As a side note, you'll probably also see the error output on the web server error log (If using Apache which sends it stderr there).

      Familiarise yourself with the syntax of the command before trying to embed it in a script.

      Mark

        Try replacing line 6 with:

            $dumpCommand.=" -e -f -u $user -p$password";    // -f to force dump even if errors

          As dbchip2000 points out, you can have as many spaces between the "-u" and the username as you want, but there must be zero spaces between the "-p" flag and the password.

            thank you very much for all the help but i manage to find the 'error'...
            i called my 'tech support' (oh how i wish that i could call them that way 🙂) and they told me that i should specify host name..... of course......
            so i was trying to do

            $dumpCommand='HOST NAME/usr/bin/mysqldump';
            ...

            but the answer was in -h argument so finally my code goes:

            $user="*********";
            $password="*****";
            $database="*********";
            
            $dumpCommand='/usr/bin/mysqldump';
                $dumpCommand.=" -e -f -h host.name.com -u$user -p$password";
                $dumpCommand.=" $database";
                $dumpCommand.=" > bekap.sql";
            
            $results=$dumpCommand;
            exec($dumpCommand);
            echo "result: ".$results; 

            oh and by the way, those spaces between -p and password were typo... just like the title of this post.... i mean, 'crates' 🙂 hahahaha, moron! 🙂 sorry for that 🙂
            thanks to all of you one more time!
            kisses*

              knucklehead wrote:

              just like the title of this post.... i mean, 'crates' 🙂 hahahaha, moron! 🙂 sorry for that 🙂

              What typo?? Are you losing your mind now? :evilgrin:

                bradgrafelman wrote:

                What typo?? Are you losing your mind now? :evilgrin:

                why of course! i think i already lost all the common sense for logical thinking... there's one script that is providing me hemroids for weeks now hahahahaha 🙂 also i'm a bit ashamed of myself now 🙂

                  Write a Reply...