CodeIgniter Forums

Full Version: how to create backup database
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi gays
i want careate backup pdo database
my code:

PHP Code:
function backup()
    {
        
$prefs = array(
 
       'tables'        => array('category'),   // 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
);

        
// Load the DB utility class
        
$this->load->dbutil();

        
// Backup your entire database and assign it to a variable
        
$backup =& $this->dbutil->backup($prefs);

        
// Load the file helper and write the file to your server
        
$this->load->helper('file');
        
write_file('./mybackup.gz'$backup);

        
// Load the download helper and send the file to your desktop
        
$this->load->helper('download');
        
force_download('mybackup.gz'$backup);
    } 

error:
Unsupported feature of the database platform you are using.

Filename: C:\xampp\htdocs\chercknevis\system\database\drivers\pdo\pdo_utility.php
Line Number: 97



please help me
tanx Huh
What version of codeigniter are you using? My pdo_utility.php file doesn't even have 97 lines of code in it.
Probably 2.x, but the result doesn't change in 3.0.

The backup feature as implemented in MySQLi (and maybe some of the other drivers) reads the structure and data of the tables and outputs very specific text to a .sql file to recreate that structure and insert the data. If this could be implemented for PDO, it would have to be implemented on the sub-driver level, since the backup is raw SQL, and can't be abstracted.

You might be able to create your own backup method which generates a migration file to recreate the database using dbforge and query builder (or active record in 2.x).