4

I want to backup a table in my database with codeigniter. I found this Guide, and programmed the function accordning to the Guide. The Problem is, that i dont get an error and i can't find the backup anywhere on my Server.

My function looks like this:

function backup_Eventtable() {
    $this->load->dbutil();
    $prefs = array(
            'tables'      => array('MYTABLE'),  // Array of tables to backup.
            'ignore'      => array(),           // List of tables to omit from the backup
            'format'      => 'txt',             // gzip, zip, txt
            'filename'    => 'mybackup.sql',    // 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'     => "\n"               // Newline character used in backup file
          );

    $backup =& $this->dbutil->backup($prefs);
    //I tried it with and without the next 2 Lines.
    $this->load->helper('file');
    write_file('/uploads/EventBackup/mybackup.sql', $backup); 
}

I just checked the appache error log and found this line:

[Fri Mar 07 14:28:37 2014] [error] [client 192.168.242.116] PHP Fatal error:  Call to undefined method CI_DB_mysql_driver::backup() in /var/www/html/kaufleuten/admin/system/application/models/eventmodel.php on line 764, referer: http://devzh2.energy.local:8093/admin/events/edit/4002

database.php looks like this:

$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "myusername";
$db['default']['password'] = "mypassword";
$db['default']['database'] = "kaufleuten_typo3";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "/var/www/html/kaufleuten/admin/cache";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
8
  • Have you checked your log file for errors? Commented Mar 7, 2014 at 13:56
  • @Pattle I checked the appache error log wich I didn't had checked before. And found the error wich I added to the Question. Commented Mar 7, 2014 at 14:17
  • But I just checked it again... and recalling the function doesn't throw the error... Commented Mar 7, 2014 at 14:21
  • What does your database.php file look like? Commented Mar 7, 2014 at 14:23
  • @Pattle added the information to the Question too.. Commented Mar 7, 2014 at 14:32

1 Answer 1

2

I had to enable the Codeigniter Log in the config.php. ($config['log_threshold'] = 2;) There I found the Error Log:

ERROR - 2014-03-07 15:33:35 --> Severity: Warning  --> fopen(uploads/EventBackup/mybackup.sql): failed to open stream: No such file or directory /var/www/html/kaufleuten/admin/system/helpers/file_helper.php 90

Changing the Path to:

 write_file('/var/www/html/kaufleuten/uploads/EventBackup/mybackup.sql', $backup);

resolved the Problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.