0

I'm getting the below error while using the below database backup code in codeigniter pdo driver :

$this->load->dbutil();
$prefs = array(
    'format' => 'zip', // gzip, zip, txt
    'filename' => 'backup_' . date('m_d_Y_H_i_s') . '.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);

$this->load->helper('file');
write_file('/path/to/' . 'dbbackup_' . date('m_d_Y_H_i_s') . '.zip', $backup);
$this->load->helper('download');
force_download('dbbackup_' . date('m_d_Y_H_i_s') . '.zip', $backup);

Unsupported feature of the database platform you are using.

Filename: E:/xampp/htdocs/pvr/system/database/drivers/pdo/pdo_utility.php

Line Number: 60

In mysqli server using this code I'm getting the database backup but in pdo getting this error so please help me to get database backup in pdo driver

7
  • 2
    "while using database backup code" - What code? Please show us the code that causes this error and you might also want to include what database you're using (since that seems to be directly relevant to the error message)? Please read: How to create a Minimal, Complete, and Verifiable example and also How do I ask a good question? Commented Feb 22, 2019 at 10:45
  • Please tell me CI version? Commented Feb 22, 2019 at 10:48
  • 3.1.10 my CI version Commented Feb 22, 2019 at 10:52
  • You still haven't told us what database platform you are using. As it says in the manual about dbutil->backup(), "This feature is only available for MySQL and Interbase/Firebird databases" Commented Feb 22, 2019 at 11:31
  • Im using pdo for it Commented Feb 22, 2019 at 11:35

1 Answer 1

1
  1. Confirm pdo of mysql enabled in php ini

  2. properly check code from https://www.codeigniter.com/userguide3/database/utilities.html?

https://www.codeigniter.com/userguide3/database/configuration.html?

  1. try this code it 100% working

controller/DATABASE_BACKUP.php

<?php
    class DATABASE_BACKUP extends CI_Controller {

        public function index()
        {
            $this->load->database();

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

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

            // 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);
        }
    }
?>

my database configuration config/database.php

<?php
    $active_group = 'default';
    $query_builder = TRUE;

    $db['default'] = array(
        'dsn'   => '',
        'hostname' => 'localhost',
        'username' => 'root',
        'password' => '',
        'database' => 'faker_db',
        'dbdriver' => 'mysqli',
        'dbprefix' => '',
        'pconnect' => FALSE,
        'db_debug' => (ENVIRONMENT !== 'production'),
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt' => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE,
        'failover' => array(),
        'save_queries' => TRUE 
    );
?>
Sign up to request clarification or add additional context in comments.

2 Comments

Please provide proper attribution for the code you copied.
i can download database backup in mysqli but i want it in pdo

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.