我在 codeigniter 中连接两个数据库。我的database.php配置如下。
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'dvrs',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
$db['orcl_db'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'mvrs',
'password' => 'mvrs',
'database' => 'MVRS',
'dbdriver' => 'oci8',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
现在我正在自动加载默认数据库,并使用
按需在相应模型中加载 orcl_db$this->orclDB = $this->database->load("orcl_db", TRUE);
我正在连接到两个数据库并成功运行查询。
我需要确保 oracle 服务器在连接之前可用,并在服务器不可用/没有响应时显示正确的错误消息。
执行此操作的最佳方法是什么?
最佳答案
以下是确保它的代码。
$this->orclDB = $this->load->database('orcl_db', TRUE);
if (!$this->orclDB ->initialize()) {
$response["status"] = false;
$response["message"] = "Oracle DB is not available.";
}
关于php - 在 Codeigniter 中连接两个数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32331408/