将codeigniter连接到数据库oracle服务器

时间:2018-12-26 09:31:55

标签: oracle codeigniter

我在将Codeigniter 3与其他计算机上的数据库oracle服务器之间连接时遇到一些问题

我尝试了3次这样的连接:

1

$active_group = 'oracle';  
$conn = "(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = xyz)))";
...
'hostname' => $conn,
'dbdriver' => 'oci8',
...

并显示错误“您在config / database.php文件中指定了无效的数据库连接组(oracle)。”

2

$active_group = 'default';
$conn = "(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = xyz)))";
...
'hostname' => $conn,
'dbdriver' => 'oci8',
...

并收到错误“消息:使用未定义的常量OCI_COMMIT_ON_SUCCESS-假定为'OCI_COMMIT_ON_SUCCESS'(这将在以后的PHP版本中引发错误)” dan“消息:调用未定义函数oci_connect()” “文件名:C:......... \ database \ drivers \ oci8 \ oci8_driver.php”

3

我将dbdriver更改为

 'dbdriver' => 'oci8_12c',

并且出现错误“无效的数据库驱动程序”


您知道如何在不同的计算机上使用Codeigniter进行连接吗?

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

首先检查数据库驱动程序https://forum.codeigniter.com/thread-56487.html

我用于oracle的database.php就是这样

$tns = "
(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = YOUR_IP)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SID = YOUR_SID)
    )
  )
       ";
$db['oracle']['hostname'] = $tns;

您使用$this->load->database('oracle',true);时,应将其分配给变量,就像您使用第二个参数true一样。像这样

$oracle_db=$this->load->database('oracle',true);//connected with oracle
$mysql_db=$this->load->database('default',true);//connected with mysql