使用php Codeigniter的mysql转储,与godaddy的服务器问题

问题描述:

I am using php to get backup of mysql database. On localhost it's working fine and the command is run as following:

$cmd = 'D:\xampp\mysql\bin\mysqldump --user=' .$db['username'].' --password=  '. $db['password'] .'     --host='.$db['host'].'  '.$db['database'].' > '.FCPATH.$filename;
system($cmd,$return);

This works perfect when at localhost, but I want to this at godaddy hosting, so I don't know how to find the mysqldump path or how to store the .sql file.

at local my app directory is this http://localhost/backup_app/ and folder i am using to store is http://localhost/backup_app/DB_Backup but actual path that i given to store .sql file is using FCPATH i.e D:\xampp\htdocs\backup_app and I don't know how to generate this path on godaddy.

Can anyone help?

我使用php来获取mysql数据库的备份。 对于localhost,它工作正常,命令运行如下 : p>

  $ cmd ='D:\ xampp \ mysql \ bin \ mysqldump --user ='。$ db ['username']。'  --password ='。  $ db ['password']。' 主机= '$分贝[ '主机']'。  '$ DB [ '数据库'。'  >  '.FCPATH。$ filename; 
system($ cmd,$ return); 
  code>  pre> 
 
 

这在localhost时效果很好,但我想在godaddy托管中这样做, 所以我不知道如何找到mysqldump路径或如何存储.sql文件。 p>

在本地我的app目录下这是 http:// localhost / backup_app / 和文件夹 http:// localhost / backup_app / DB_Backup 但我给存储.sql文件的实际路径是使用FCPATH i.e D:\ xampp \ htdocs \ backup_app 我不知道如何在godaddy上生成这个路径。 p>

任何人都可以帮忙吗? p> div>

You tagged to question with codeigniter. Once I done this. I am sharing the code with you, lets hope it will work for your version of CI.

In version 2.x, CI dbforge class not supporting to mysqli driver, so I set the driver to mysql.

$db['group_one']['dbdriver'] = 'mysql';

Define the path in constants to store the file.

define('ADMIN_DOCS_PATH','adminDocs/');

The code to take backup and store the file on disk.

public function getDatabaseBackup()
{
    $this->db = $this->load->database('group_one', TRUE);
    $this->load->dbutil();
    $doc_name = 'DatabaseBackup'.date('YmdHis').'.sql.zip';
    $prefs = array(
            'tables'      => array(),           // Array of tables to backup.
            'ignore'      => array(),           // List of tables to omit from the backup
            'format'      => 'zip',             // gzip, zip, txt
            'filename'    => $doc_name,         // File name - NEEDED ONLY WITH ZIP FILES
            'add_drop'    => TRUE,              // Whether to add DROP TABLE statements to backup file
            'add_insert'  => TRUE,              // Whether to add INSERT data to backup file
            'newline'     => "
"               // Newline character used in backup file
          );
    $backup =& $this->dbutil->backup($prefs);
    $this->load->helper('file');
    write_file('./'.ADMIN_DOCS_PATH.$doc_name, $backup);
}

Try this, also confirm your CI version and its support to dbforge class to download the database dump.