CodeIgniter - ActiveRecords and Oracle - configuration

I'm having a problem with ActiveRecords - CI add parentheses to table names - so oracle is returning errors.

Here's some info on how to fix it :)

first set up your database

My old dns config looks like this:

$dsn = array(
    'phptype'   => 'oci8',
    'hostspec'  => '192.xx.215.xx',
    'service'   => 'yyyyy',
    'port'      => '1521',
    'username'  => 'zzzzz',
    'password'  => 'aaaaa'
);

      

So, I added in the application\config\database.php

following:

$db['oracle']['hostname'] = "192.xx.215.xx/yyyyy";
$db['oracle']['username'] = "zzzzz";
$db['oracle']['password'] = "ttttt";
$db['oracle']['database'] = "dbname.table";
$db['oracle']['dbdriver'] = "oci8";
$db['oracle']['dbprefix'] = "";
$db['oracle']['pconnect'] = FALSE; //must be false
$db['oracle']['db_debug'] = TRUE;
$db['oracle']['cache_on'] = FALSE;
$db['oracle']['cachedir'] = "";
$db['oracle']['char_set'] = "utf8";
$db['oracle']['dbcollat'] = "utf8_general_ci";

      

c system\database\drivers\oci8\oci8_driver.php

replace string

return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);

      

from

// remove duplicates if the user already included the escape
$str = preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
$str =  rtrim($str,'"');
$str =  ltrim($str,'"');
$str =  str_replace('"."', '.', $str);

return $str;

      

Now you can name your model

$this->oracle = $this->load->database('oracle', TRUE);

      

Oracle and Ci should now work! :)

+1


source to share





All Articles