【问题标题】:Database Backup not working in codeignator using pdo数据库备份在使用 pdo 的 codeigniter 中不起作用
【发布时间】:2019-07-16 10:39:51
【问题描述】:

在 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 驱动程序中获取数据库备份

【问题讨论】:

标签: php sql codeigniter pdo


【解决方案1】:
  1. 确认php ini中启用mysql的pdo

  2. 正确检查代码 https://www.codeigniter.com/userguide3/database/utilities.html?

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

  1. 试试这个代码它 100% 工作

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

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

【讨论】:

  • 请为您复制的代码提供正确的归属。
  • 我可以在 mysqli 中下载数据库备份,但我希望它在 pdo 中
猜你喜欢
  • 2015-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-01
  • 2013-01-29
  • 1970-01-01
相关资源
最近更新 更多