Jump to content
Sign in to follow this  
JustMike

mysqldump creates empty file

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...

Share this post


Link to post
Share on other sites

The first thing I would do would be to print out that system command and then run it on the command line to see if there are any errors.

Share this post


Link to post
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;

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...