2

Currently I'm working with oracle db using codeigniter. I'm newbie to this db, when i try to make the connection. I got this error.

A PHP Error was encountered

Severity: Notice
Message: Use of undefined constant OCI_COMMIT_ON_SUCCESS - assumed 'OCI_COMMIT_ON_SUCCESS'
Filename: database/DB.php
Line Number: 144 

I've already enable extension in php.ini

;extension=php_mysqli.dll
extension=php_oci8.dll      ; Use with Oracle 10gR2 Instant Client
;extension=php_oci8_11g.dll  ; Use with Oracle 11gR2 Instant Client

Below is my code for database.php :

$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'xxx.xxx.x.xx';
$db['default']['username'] = 'xxxx';
$db['default']['password'] = 'xxxx';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'oci8';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

Below is the code at controller :

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {


    function __construct()  {
            parent::__construct(); 
    }

    function index()        {
            $this->db = $this->load->database('default',TRUE);

            if (!empty($this->db))
                echo "Connected!"."\n";
            else
                echo "Closed"."\n";
    }
}

I've been stuck on this problem almost 2 weeks. I also already searched the solution but nothing's work. can you help me?

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358

1 Answers1

2

I know it is a cold case, but some people may still work with Oracle 10g & 11g these days.

A few points to check:

  • You're saying "in php.ini", but did you uncomment it in the webserver one? Or just in the cli one? (there are two php.ini, depending on the SAPI).

  • Can you see oci8 in the output of phpinfo() when run from within a web page?

  • Did you ever try to activate the php_oci8_11g.dll module in the webserver's php.ini, instead of php_oci8.dll ?

  • Did you try a simple unit test, like: <?php echo OCI_COMMIT_ON_SUCCESS; ?>

  • Try that above one-liner from the command line, after activating either oci8 module in the cli php.ini (no need to restart anything if cli, obviously) instead of pulling out the "big weapon" = the full webapp.

  • If you ever set this up on Ubuntu, make sure that LD_LIBRARY_PATH was defined in /etc/apache2/envvars, to point to the instantclient library (downloaded from oracle.com), e.g. /opt/oracle/instantclient_12_2

  • Obviously restart the webserver after each modification in php.ini for server.

Fabien Haddadi
  • 1,814
  • 17
  • 22
  • BTW, the expected value for OCI_COMMIT_ON_SUCCESS is 32 (=0x20) – Fabien Haddadi Jan 30 '19 at 12:44
  • If Instant Client is the only Oracle software installed, it is easier to use [ldconfig](https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html#ic_x64_inst) to globally update the library search path, instead of manually setting the Apache environment. – Christopher Jones Feb 05 '19 at 23:11