使用pdo在Codeignator中无法使用数据库备份

时间:2019-02-22 10:43:34

标签: php sql codeigniter pdo

在codeigniter pdo驱动程序中使用以下数据库备份代码时,出现以下错误:

$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);
  

您正在使用的数据库平台的不受支持的功能。

     

文件名:E:/xampp/htdocs/pvr/system/database/drivers/pdo/pdo_utility.php

     

行号:60

在使用此代码的mysqli服务器中,我正在获取数据库备份,但在pdo中却出现此错误,因此请帮助我在pdo驱动程序中获取数据库备份

1 个答案:

答案 0 :(得分:0)

  1. 确认在php ini中启用了mysql的pdo

  2. 从以下位置正确检查代码 https://www.codeigniter.com/userguide3/database/utilities.html

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

  1. 尝试此代码,使其100%工作

controller / DATABASE_BACKUP.php

WHERE put(t1.ifrs_stage_date_at_start,datetime20.-L) like '31DEC2017:%'

我的数据库配置 config / database.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);
        }
    }
?>