Jump to content

mysqldump creates empty file


JustMike
 Share

Recommended Posts

Hi, I'm trying to create a php class that creates a database backup but the result is an empty file.

 

Here is my code so far:

Note: The uploadBackup() method is not ready yet, I'm still trying to figure out the createbackup() method...

<?phpclass dropboxbackup{    // temp directiry    public $tempDir;        // MySQL DB connection data (username, password, database, host and prefix)    private $user;    private $password;    private $dbName;    private $dbHost;            //DropBox Information    private $dropbox_user;        private    $dropbox_pass;    private    $dropbox_loc;            //File Information    private $fileName;    private $sqlFile;        public $dbPrefix;        private $d = DIRECTORY_SEPARATOR;        public function __construct($td, $u, $p, $n, $h, $p){            $this->tempDir = $td;        $this->user = $u;        $this->password = $p;        $this->dbName = $n;        $this->dbHost = $h;        $this->dbPrefix = $p;    }        public function createbackup(){                $creationDate = date('Y_m_d');        $this->sqlFile = $this->tempDir."{$this->d}".$this->dbPrefix."_".$creationDate.".sql";        //$actualCreateBackup = "mysqldump -u".$this->user."-p".$this->password." ".$this->dbName." > ".$sqlFile;        //$actualCreateBackup = "C:WebServermysqlbinmysqldump  --opt -h".$this->dbHost." -u".$this->user."-p".$this->password." ".$this->dbName." > ".$sqlFile;        //$actualCreateBackup = "mysqldump -h".$this->dbHost." -u".$this->user." -p'".$this->password."' ".$this->dbName." > ".$sqlFile;        $actualCreateBackup = "C:WebServermysqlbinmysqldump  --opt --host=".$this->dbHost." --user=".$this->user." --password=".$this->password." ".$this->dbName." > ".$this->sqlFile;        //shell_exec($actualCreateBackup);        exec($actualCreateBackup);    }        public function deleteBackup(){            unlink($this->sqlFile);    }        public function uploadBackup(){        try {                // Upload database backup to Dropbox                    $uploader = new DropboxUploader($this->dropbox_user, $this->dropbox_pass);                    $uploader->upload($this->sqlFile, $this->dropbox_loc);            }catch(Exception $e){                    die($e->getMessage());            }    }    }

and the class is instantiated in index.php :

<?phpinclude("dropboxbackup.php");$a = new dropboxbackup('temp', 'root', '', 'db_name', 'localhost', 'prefix_');$a->createbackup();?>

After I hit index.php I get an empty file in the temp directory named prefix__2014_06_02.sql

 

What I'm doing wrong? I searched this problem on google but I still can't figure it out... the root user is set to ALL PRIVILEGES, the database information is correct...

Link to comment
Share on other sites

Thanks, I solved the problem.

There was a error in the __construct (I had the same name for two variables) and one in the createbackup method... the final mysqldump command is this:

$actualCreateBackup = "mysqldump  --opt --host=".$this->dbHost." --user=".$this->user." --password=".$this->password." ".$this->dbName." > ".$this->sqlFile;
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...