如何在Codeigniter中配置多个数据库和使用故障转移 [英] How to configure multiple database and using failover in Codeigniter

查看:134
本文介绍了如何在Codeigniter中配置多个数据库和使用故障转移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Codeigniter3.0.4作为文档,条件是我无法配置多个数据库并使用'failover'=> array()

I've used Codeigniter3.0.4 as the document provide I can't configure multiple database and using 'failover' => array().

我发现了错误您尚未选择要连接的数据库类型。如果我使用此选项,则在我的网站上

I found an errros You have not selected a database type to connect to. on my website if I used this options

$active_group = 'default';
$active_record = TRUE;
$db['default']['failover'] = array(
    array(
        'hostname' => 'localhost',
        'username' => 'root',
        'password' => '',
        'database' => 'com',
        'dbdriver' => 'mysqli',
        'dbprefix' => '',
        'pconnect' => TRUE,
        'db_debug' => TRUE,
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt' => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE
    ),
    array(
        'hostname' => 'localhost2',
        'username' => 'root',
        'password' => '',
        'database' => 'ABC',
        'dbdriver' => 'mysqli',
        'dbprefix' => '',
        'pconnect' => TRUE,
        'db_debug' => TRUE,
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt' => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE
    )
);

请帮助我该怎么做。

推荐答案

您必须设置数据库的默认/组配置。如果默认/组配置失败,则只有它会检查故障转移

You have to set the default/group configuration of database. If default/group configuration fails then only it'll check the failover

$db['default'] = array(
        'dsn'   => '',
        'hostname' => 'localhost',
        'username' => 'root',
        'password' => '',
        'database' => 'database_name',
        'dbdriver' => 'mysqli',
        'dbprefix' => '',
        'pconnect' => TRUE,
        'db_debug' => TRUE,
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt' => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE,
        'failover' => array(
            array(
                    'hostname' => 'localhost1',
                    'username' => '',
                    'password' => '',
                    'database' => '',
                    'dbdriver' => 'mysqli',
                    'dbprefix' => '',
                    'pconnect' => TRUE,
                    'db_debug' => TRUE,
                    'cache_on' => FALSE,
                    'cachedir' => '',
                    'char_set' => 'utf8',
                    'dbcollat' => 'utf8_general_ci',
                    'swap_pre' => '',
                    'encrypt' => FALSE,
                    'compress' => FALSE,
                    'stricton' => FALSE
            ),
            array(
                    'hostname' => 'localhost2',
                    'username' => '',
                    'password' => '',
                    'database' => '',
                    'dbdriver' => 'mysqli',
                    'dbprefix' => '',
                    'pconnect' => TRUE,
                    'db_debug' => TRUE,
                    'cache_on' => FALSE,
                    'cachedir' => '',
                    'char_set' => 'utf8',
                    'dbcollat' => 'utf8_general_ci',
                    'swap_pre' => '',
                    'encrypt' => FALSE,
                    'compress' => FALSE,
                    'stricton' => FALSE
            )
        )
);

这篇关于如何在Codeigniter中配置多个数据库和使用故障转移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆