• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Oracle Database Connection with PHP 7.3.5 Latest Version

#1
Currently I'm working with oracle 11g db using codeigniter 3X and PHP Version 7.3.5 . I'm newbie to this db, when i try to make the connection. I got this error.

A PHP Error was encountered.


Code:
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


Code:
;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 [b]database.php :[/b]


Code:
$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 [b]controller :[/b]


Code:
<?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 1 weeks. I also already searched the solution but nothing's work. can you help me ?

Some Developers Said [b]below solution, i'am also try that solution  but its not work for me. [/b]

Ans : 

It seems your oracle setup is not completed.


I'm not sure, but this PDF http://www.oracle.com/technetwork/topics...98250.html may help you.

So Can you Guide me  how to setup the oracle 11g Edition with PHP 7.3.5 Latest Version ?
Reply

#2
OCI_COMMIT_ON_SUCCESS is a constant declared in the Oracle PHP extension. Are you sure you have that installed correctly? Is it enabled in php.ini? Can you confirm that you can connect to the database manually with oci_connect?

If you don't have the extension, then you'll need to install it.

A list of steps to debug an installation can be found here.

You should also look at the php error log looking for any errors related to Oracle and the loading of the extension.

What OS is the webserver on?
Reply

#3
(05-09-2019, 10:11 PM)eswarrao Wrote:
Code:
;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

In my php.ini file I'm using the following settings:
;extension=oci8_12c
extension=oci8_11g


Also make sure you've installed the dlls in your php server.
I'm using xampp so I have 2 dlls in the xampp/php/ext directory:
php_oci8_11g.dll
php_oci8_12c.dll


Below is my code for [b]database.php :[/b]

Code:
$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;

Do you have tnsnames setup correctly?
Go to a command line and try:
tnsping yourdbname

If you get a successful response then you can just add this:
$db['default']['dsn'] = 'yourdbname';

You don't need $db['default']['hostname'] to be set to anything.
You do have to set 
$db['default']['username'] = 'xxxx';
$db['default']['password'] = 'xxxx';
$db['default']['dbdriver'] = 'oci8';


If you don't have tnsnames setup correctly 
then you can try setting the dns to:
$db['default']['dsn'] = '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = yourdbname))'
Just make sure the host, port and yourdbname are set to your Oracle database instance.

Check your character set (select * from nls_database_parameters) UTF8 in Oracle is AL32UTF8. But it doesn't seem to be a problem to make a connection anyways.

$db['default']['char_set'] = 'al32utf8';
$db['default']['dbcollat'] = 'al32utf8';


Below is the code at [b]controller :[/b]


Code:
<?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";
   }
}

Your controller looks fine.

I ran into a problem with codeignite doing the following when trying to select a table:

select * from "tablename";

This forces Oracle to search for a table with lowercase letters. The problem is Oracle stores table names and column names in uppercase. Maybe you won't have this problem. To workaround this I created a view in lowercase letters for both the name and column names. 
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.