How to connect an Oracle database from PHP
Forth link in google after searching for your exact questions brought up the following link: http://me2learn.wordpress.com/2008/10/18/connect-php-with-oracle-database/
<?php
$db = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.34)(PORT = 1521)))(CONNECT_DATA=(SID=orcl)))" ;
if($c = OCILogon("system", "your database password", $db))
{
echo "Successfully connected to Oracle.\n";
OCILogoff($c);
}
else
{
$err = OCIError();
echo "Connection failed." . $err[text];
}
?>
How do I connect PHP 7.x to Oracle database on RedHat / CentOS?
Having struggled for over a week to figure this out, here is a summary of what ultimately worked. I hope this helps somebody else.
These instructions apply to RedHat / CentOS Linux installations. My experience was that the instructions for RedHat / CentOS were slightly different to other Linux installations. AVOID the Oracle guidance... They did not help at all!
Step1:
I followed the instructions on this excellent website to install PHP 7.3 and additional Remi rpm packages:https://tecadmin.net/install-php7-on-centos7/
Step 2: I then used the Remi repository (see step 1) to install the oci8 extension:
$ sudo yum --enablerepo=remi-php73 install php-oci8
Step 3: We now need to install the oracle instant client 18.3 packages. This is very nicely explained on this website: https://qiita.com/tkprof/items/2a4eb868f45fb5759110
$ cd /etc/yum.repos.d
$ sudo wget http://yum.oracle.com/public-yum-ol7.repo
$ sudo wget http://yum.oracle.com/RPM-GPG-KEY-oracle-ol7
$ sudo rpm --import RPM-GPG-KEY-oracle-ol7
$ sudo yum-config-manager --enable ol7_oracle_instantclient
$ sudo yum install oracle-instantclient18.3-basic
$ sudo yum install oracle-instantclient18.3-devel
$ sudo yum install oracle-instantclient18.3-jdbc
$ sudo yum install oracle-instantclient18.3-sqlplus
$ sudo yum list oracle-instantclient*
Step 4: The oracle files have been created in /usr/lib/oracle/18.3 We now need to create a symlink so that the oracle files are included when the server is running:
$ sudo sh -c "echo /usr/lib/oracle/18.3/client64/lib > /etc/ld.so.conf.d/oracle-instantclient.conf"
$ sudo ldconfig
Step 5: Restart the server $ sudo systemctl stop httpd
$ sudo systemctl start httpd
Step 6: We can now create a simple php file that tests the connection to Oracle:<?php
$conn = oci_connect("username", "password", "//url/SID");
if (!$conn) {
echo "oci8 working! However the following errors occurred: <br>";
$m = oci_error();
echo $m['message'], "\n";
exit;
} else {
print "Connected to Oracle!";
}
// Close the Oracle connection
oci_close($conn);
If you get a system error then the installation has not worked. How to connect with Oracle database in CodeIgniter
You can try the following options:
Option 01:
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => '192.168.0.109:1521/orcl', //hostname:db_port/service_name
//'hostname' => 'localhost:1521/orcl',
'username' => 'db_username',
'password' => 'db_password',
'database' => 'db_name',
'dbdriver' => 'oci8',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Option 02:$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.246)(PORT=1521))(CONNECT_DATA=(SID=orcl)))';
$db['default']['username'] = 'db_username';
$db['default']['password'] = 'db_password';
$db['default']['database'] = 'db_name';
$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;
Hope this will help you
Related Topics
How to Access My Wamp Server on Another Local Computer
Jquery Ajax Form Data Serialize Using PHP
Check If Youtube and Vimeo-Clips Are Valid
How to Disable the Back Browser Button After User Press Logout and Destroy Session
Php: How to Read a File Live That Is Constantly Being Written To
Force Download via Ajax and PHP
Insert Backbone.Js Model into MySQL Database
How to Remove Email Addresses and Links from a String in PHP
Sending JavaScript Object to PHP via Ajax
Php, How to Get Current Date in Certain Format
PHP Explode Array Then Loop Through Values and Output to Variable
Convert Windows Timestamp to Date Using PHP on a Linux Box
Phpmyadmin Failed to Set Session Cookie. Maybe You Are Using Http Instead of Https