codeigniter / ci / oracle database.php 的設定方式 / utf8 / big5 粉難搞

$db['oci']['hostname'] = "//IP_ADDRESS/INSTANT_NAME";
$db['oci']['username'] = "USERNAME";
$db['oci']['password'] = "PASSWORD";
$db['oci']['database'] = "INSTANT_NAME";
$db['oci']['dbdriver'] = "oci8";
$db['oci']['dbprefix'] = "";
$db['oci']['pconnect'] = TRUE;
$db['oci']['db_debug'] = TRUE;
$db['oci']['cache_on'] = FALSE;
$db['oci']['cachedir'] = "";
$db['oci']['char_set'] = "utf8"; // database 是 UTF8
$db['oci']['char_set'] = "ZHT16BIG5"; // database 是 big5

$db['oci']['dbcollat'] = "utf8_general_ci";

記得 codeigniter 的 /system/database/drivers/oci8/oci8_driver.php 這個檔要改一下

2009.0303 補充, 若要連 oracle standby database.php 要改成這樣 用 service name ( 看那個 tnsnames.ora )

擷取-oracle-standby-ci

Codeigniter 聯接 Oracle database 要改的地方

Codeigniter version 1.6.3
Oracle version 10.2.0.4 use oci8

遇到這個 error :
Message: ocifetchinto() expects parameter 1 to be resource, null given

// 這個檔 \system\database\DB_driver.php 改成..

// $RES->num_rows	= $RES->num_rows();

if ($this->dbdriver == 'oci8')
{
  $RES->stmt_id		= $this->stmt_id;
  $RES->curs_id		= NULL;
  $RES->limit_used	= $this->limit_used;
}
$RES->num_rows	= $RES->num_rows();


解決沒有使用 UTF8 的問題

// 這個檔 \system\database\drivers\oci8\oci8_driver.php
// 改兩個地方:
function db_connect() 的
return @ocilogon($this->username, $this->password, $this->hostname,$this->char_set);

db_pconnect() 的
return @ociplogon($this->username, $this->password, $this->hostname,$this->char_set);


codeigniter 的連線設定

$db['default']['hostname'] = '//172.20.10.6/DB1';
$db['default']['username'] = "scott";
$db['default']['password'] = "*****";
$db['default']['database'] = "DB1";
$db['default']['dbdriver'] = "oci8";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = TRUE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

相關聯結:

http://download.oracle.com/docs/cd/B25329_01/doc/install.102/b25144/toc.htm#BABBGFIC


codeigniter 的 oracle driver 問題還不少, 同一隻程式第二個 sql select 的結果跟第一個一樣…

要改

/system/database/drivers/oci8/oci8_driver.php
的159行
if ( ! is_resource($this->stmt_id))
{
  $this->stmt_id = ociparse($this->conn_id, $this->_prep_query($sql));
}
改成
$this->stmt_id = ociparse($this->conn_id, $this->_prep_query($sql));
就夠了.