I have made a library function for backing up a database, but for some reason I’m getting ‘Call to a member function on a non-object’. If I remove ‘CI->’ I get the same error. See where the comment is. Anyone got an idea why this happens?
class System {
var $CI;
/**
* Constructor
*
*/
function System()
{
$this->CI =& get_instance();
log_message('debug', "System Class Initialized");
}
function backupDB($db_backup_path='./backups_db/', $db_name='dbname')
{
// Load the DB utility class
$this->CI->load->dbutil();
$time = date('d-m-Y_H-i-s');
$filename = $db_name.'_'.$time;
$prefs = array( 'tables' => array(),
'format' => 'zip', // gzip, zip, txt
'filename' => $filename .'.sql', // File name - NEEDED ONLY WITH ZIP FILES
'add_drop' => FALSE, // 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
);
$do = $this->CI->dbutil->backup($prefs); // <-- SCRIPT CHOKES HERE
// Backup your entire database and assign it to a variable
$backup =& $do;
// Load the file helper and write the file to your server
$this->CI->load->helper('file');
if (write_file($db_backup_path . $filename .'.sql.zip', $backup))
{
return TRUE;
}
}
}