• [deleted]

I'd start by printing instead of exec()-ing:
echo ("$a -u$b -p$c $db > d:\test1.dump");

to see if you are doing what you think you are doing.

    After some playing around and surfing ..
    I came up with the following solution, maybe you can use some of it ...
    This was written for a Win32 solution ..
    I have it working correctly on my Windows2000 laptop.

    first I have a page with a form:

    <form method="post" action="out.php">
    <input type="Submit" value="Dump!" name="dumpit">
    </form>

    That calls out.php :

    <?php
    //dB Connection information
    $db = mysql_connect("localhost","USERNAME","PASSWORD") or die("Connection failed:".mysql_error());
    mysql_select_db("DATABASENAME",$db) or die ("$dBConnectErr;");

    if ($dumpit)
    {
    $dump = "c:\phpdev\mysql\bin\mysqldump --opt $db > backupfile.sql";
    shell_exec("cmd /c $dump");

    }

    ?>

    Thanks!
    Dave

      • [deleted]

      This I find puzzling:

      $dump = "c:\phpdev\mysql\bin\mysqldump --opt $db > backupfile.sql";

      Are you telling me that mysqldump can use PHP's database connection identifier ($db)?

      mysqldump creates it's own connection to the database.

        vincent wrote:

        This I find puzzling:
        Are you telling me that mysqldump can use >PHP's database connection identifier ($db)?

        I'm no Authority on PHP or MySQL, this is just the script I got working on my local machine. The way I see it, PHP just passes that variable ($db) out in the string
        ( $dump = "c:\phpdev\mysql\bin\mysqldump --opt $db > backupfile.sql"; )
        that it passes to the command line.

        vincent wrote:

        mysqldump creates it's own connection to >the database.
        I understand that, but the way I read the question, they were looking for a solution using PHP.

        Did you try my example? I'd really like to know if anyone feels my coding practice was incorrect. It seems to work for me (but isnt it always amazing how you can have a code snippet work for yourself, but when you want to show it off it breaks?)
        hehehehe

        Thanks!
        Dave

          • [deleted]

          My point was that mysqldump does NOT require a PHP database connection.

          ergo, you can just put:
          <?
          $dump = "c:\phpdev\mysql\bin\mysqldump mydatabase --opt > backupfile.sql";
          shell_exec("cmd /c $dump");
          ?>

            vincent wrote:

            My point was that mysqldump does NOT >require a PHP database connection.

            ergo, you can just put:
            <?
            $dump = "c:\phpdev\mysql\bin\mysqldump
            mydatabase --opt > backupfile.sql";
            shell_exec("cmd /c $dump");
            ?>

            well, well, you are correct (I was NEVER saying you were wrong) that works wonderfully. Just move the databasename to the other side of the "--opt".

            Using the script with a variable would allow you to backup multiple databases .. but either way it works ..

            very good! thanks Vincent!

            Dave

              Hi,

              Thanks for your responses.
              Sorry I guess I missed out an important piece of information.
              I could have used a batch program to write this..not even requiring php but I NEEDED to keep a backup of 9 files based on the date.

              I have since read that php exec and system functions are causing problems with win2000 and IIS.

              I've decided to use perl instead.

              Thanks again 🙂.

                Hi Vincent,

                Thanks for your suggestion.

                Seeing that I wanted to resolve what my issue is I took your suggestion.

                echo ("$a -u$b -p$c $db d:\test1.dump");
                In code produced the following:

                X-Powered-By: PHP/4.0.6
                Content-type: text/html

                c:\mysql\bin\mysqldump -uroot -pxxxxx forum > d:/test1.dump

                In fact the only thing I changed in the code was the direction of my slash for d:/test1.dump.

                This echo statement is correct! I will 'assume' that my code is okay.

                What I have read was that php exec and system functions don't seem to work properly in win2000. That is really too bad.

                I tried using shell_exec that does not work either...same error.

                If you have any other suggestion please feel free to pass them along, and I will try them out and let you know the results.

                Thanks.

                  • [deleted]

                  I am usually right....

                  ... and modest too! :-)

                    Hi Dave,

                    Thanks a million your code did work.

                    I actually didn't use the entire code but the last statement:

                    shell_exec ("cmd /c $dump")

                    This was my problem..I have no idea yet!! I will look into why you have to use cmd /c for this program to work.

                    I actually did some tingering around and the program will run with just exec ("cmd /c $dump") but it won't work without cmd /c.

                    Thank you again.

                      great! glad it worked for you ..

                      have a great weekend!

                      Dave

                        Write a Reply...