Bader H Al Rayyes
Bader H Al Rayyes

Reputation: 522

backup .sql file is empty

i am trying to backup mysql database by using this code

    include ("functions_cp/f_connection.php");

        Sqlconnection() ;



    $dbname = "Reservebox";
    $dbhost = "localhost";
    $dbuser = "root";
    $dbpass = "123";



$backupFile =  $dbname . date("Y-m-d-H-i-s") . '.sql';

$command = 'mysqldump -h' .  $dbhost . ' -u ' . $dbuser . '-p =' . $dbpass . ' '. $dbname . ' > ' . $backupFile ;
system($command);

the script works fine and it generates a .sql file , however this file is empty , how can i fix this problem ?

thanks

Upvotes: 0

Views: 575

Answers (2)

alecwhardy
alecwhardy

Reputation: 2718

Probably a file permissions error. Check that whatever user PHP and MySQL are running as have the permissions to write the file. FOr troubleshooting purposes, chmod the directory to 0777 and see if that fixes the problem. If so, chown the directory to whatever user MySQL is running as.

Upvotes: 1

Ben Lee
Ben Lee

Reputation: 53319

Don't put a space or equals sign between the -p and the password. Also, you are missing a space before the -p.

$command = 'mysqldump -h' .  $dbhost . ' -u ' . $dbuser . ' -p' . $dbpass . ' '. $dbname . ' > ' . $backupFile ;

Upvotes: 1

Related Questions