如何在Codeigniter中配置多个数据库并使用故障转移

时间:2016-02-17 14:46:08

标签: codeigniter

我使用Codeigniter3.0.4作为文档提供我无法配置多个数据库并使用'failover'=>阵列()

我发现了一个errros 如果我使用了这个选项,你的网站上没有选择要连接的数据库类型。

 d.likes.exists?(user_id:  current_user.id)

请帮助我该怎么做。

1 个答案:

答案 0 :(得分:1)

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

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