Results 1 to 3 of 3

Thread: MySQL Database Backup

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    266

    Question MySQL Database Backup

    I wish to restore the data of tables of my database into Excel(.xls) or any other format. Below is my code.

    PHP Code:
    <?php

    mysql_connect
    ("localhost","root","");
    mysql_select_db("test");

    $dbname    "test";
    $dbhost    "localhost";
    $dbuser    "root";
    $dbpass    "";
    $backupFile    "restore";

    $backupFile $dbname date("Y-m-d-H-i-s") . '.gz';
    $command "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile";
    system($command);

    ?>
    There is no error. But I cannot see the output. Please tell me what is wrong with my code. Please rectify.

    My environment is as below:
    Windows XP
    WampServer

    Thanks a lot in advance.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: MySQL Database Backup

    first, you're using the shorthand option p and aren't following its rules; -p must be followed by the password (no spaces!), otherwise the console will ask you for a password as if you haven't entered it. I would suggest using --host=, --user=, and --password= instead.

    also, --opt is on by default (so you don't need to enable it) and --host defaults to localhost (assuming you're never changing the host name), just so you know. feel free to look at the documentation if you need more help using mysqldump.

    then, make sure the value of $command is correct and will be able to run (echo out $command and run it in the command prompt).

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: MySQL Database Backup

    Try using passthru instead of system to see the output.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width