php代码点火器故障转移阵列

ohfgkhjo  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(255)

我不需要故障转移连接方面的帮助,只是这个故障转移阵列可能有什么问题?我已经测试了备用数据库连接和工程伟大。问题是,当我关闭主设备时,故障转移并没有按它应该的方式连接。这是直接从代码点火器文档。有什么小技巧可以帮助你排除故障吗?

/*
 * Mysql Driver

* /

$db['mysql']['hostname'] = getenv('DB_HOST');
$db['mysql']['username'] = getenv('DB_USERNAME');
$db['mysql']['password'] = getenv('DB_PASSWORD');
$db['mysql']['database'] = getenv('DB_DATABASE');
$db['mysql']['dbdriver'] = 'mysql';
$db['mysql']['dbprefix'] = '';
$db['mysql']['pconnect'] = FALSE;
$db['mysql']['db_debug'] = FALSE;
$db['mysql']['cache_on'] = FALSE;
$db['mysql']['cachedir'] = '';
$db['mysql']['char_set'] = 'utf8';
$db['mysql']['dbcollat'] = 'utf8_general_ci';
$db['mysql']['swap_pre'] = '';
$db['mysql']['autoinit'] = TRUE;
$db['mysql']['stricton'] = FALSE;
$db['mysql']['failover'] = array(
    array(
    'hostname' => getenv('DB_HOST2'),
    'username' => getenv('DB_USERNAME2'),
    'password' => getenv('DB_PASSWORD2'),
    'database' => getenv('DB_DATABASE2'),
    'dbdriver' => 'mysql',
    '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
  )
);
7gs2gvoe

7gs2gvoe1#

必须设置默认连接,请尝试以下操作:

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'root',
    .............
);

$db['default']['failover'] = array(
            array(
                    'hostname' => 'localhost1',
                    'username' => ''
                    ..........
            ),
            array(
                    'hostname' => 'localhost2',
                    'username' => ''
                    ..........
            )
);

https://codeigniter.com/user_guide/database/configuration.html

相关问题