Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

mysqldump and php

Options
  • 09-06-2008 11:22am
    #1
    Registered Users Posts: 26,579 ✭✭✭✭


    hey i'm trying to run a mysqldump command through a php script but i'm having no joy. here's the script.

    [php]
    <?php

    include 'dbconnect.inc.php';

    $file = $DB_NAME . '_' . date("Y-m-d_H:i:s") . '.sql';

    //location of mysqldump util
    $mysqldump = '/opt/lampp/bin/mysqldump';

    $cmd = "$mysqldump --opt -h $DB_HOST $DB_NAME -u $DB_USER -p DB_PASS > $file";

    system($cmd);

    ?>
    [/php]i echoed the command and then copy and paste it into a terminal window and sure enough out popped the output file. also as far as i know system() calls aren't blocked as system('pwd') works fine.

    can anyone see anything up?


Comments

  • Closed Accounts Posts: 8 allexxei


    Check safe_mode ! If it is on - that's the problem


  • Closed Accounts Posts: 8 allexxei


    Also for $file you shoul use complete path :)


  • Closed Accounts Posts: 8 allexxei


    also, -p $password should be -p'.$password ( no space between -p and you variable) or else will promt for password


  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    allexxei wrote: »
    Check safe_mode ! If it is on - that's the problem

    safe_mode is Off.
    allexxei wrote: »
    Also for $file you shoul use complete path :)

    i agree, but this was just for testing purposes.
    allexxei wrote: »
    also, -p $password should be -p'.$password ( no space between -p and you variable) or else will promt for password

    fixed that, still ain't working :confused:


  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    ok i've changed the layout of backup.

    i now have the backup running in a perl script that runs fine and creates a mysql dump when ran from the command line, this actually works best in my favour as i now can set it up on a cron whereas i don't know if i could of done that with php due to it having to be run in a browser window.

    so i've got my backup perl script working, but i still want a html form that will allow for a manual backup of the database.

    here's the backup perl script (dbBackup.pl)

    [php]
    #!/usr/bin/perl

    use DBI;

    #MySQL login details
    my $dsn = "dbi:mysql:fat;localhost:3306";
    my $dbuser = "root"; #not using root account in real script.
    my $dbpass = "password"; #nor stupid enough to use lame password.

    #Database to backup.
    my $dbname = "fat";

    #MySQL dump directory.
    my $mysqldump = "/opt/lampp/bin/mysqldump";

    #Create dump filename
    my $fileName = $dbname;
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
    $year +=1900;
    my $timeHandle = "$year-$mon-$mday"."_"."$hour:$min:$sec";
    $fileName .= $timeHandle . ".sql";

    #backup directory
    $backupDir = "./backup";


    #do mysqldump command
    my $cmd = "$mysqldump --opt -u $dbuser -p$dbpass $dbname > $backupDir/$fileName";

    print `$cmd`;
    [/php]

    which runs from from terminal.

    now here's the php script i have for the form (doesn't really need to be php but i want to keep the file extension the same as every other file in my program is php).

    [php]
    <?php

    echo'<form method="post" action="dbBackup.pl">
    <table class="admin">
    <tr><td class="admin" colspan="2"><h2>Database backup</h2></td>
    </tr>
    <tr>
    <td class="admin" colspan="2"><input type="submit" class="subbut" value="Backup DB" /></td>
    </tr>
    </table>
    </form>';
    ?>
    [/php]

    so when i submit the form i get taken to a blank page which i expect for the moment, but no backup is made?



    *EDIT* all sorted, backup directory was writable d'oh.


  • Advertisement
Advertisement