Welcome Guest, Not a member yet? Register   Sign In
Oracle Database Connection with PHP 7.3.5 Latest Version
#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


Messages In This Thread
RE: Oracle Database Connection with PHP 7.3.5 Latest Version - by jora - 06-09-2019, 06:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB