Skip to content

Connect PHP 8 with Oracle 19C on CentOS

In this tutorial, we are going to see how to connect to Oracle database with PHP.

1 min read
A laptop connected by glowing data streams to a cluster of database disks

This screencast is to demonstrate the process of using Oracle 19 Instant Client, PHP8 and Oracle 19C on a Remote Machine. You can either connect to the container database or pluggable database.

Credit: Dhiraj Kumar Jha

Now, you can check the oracle database connection using this code snippet.

database.php
<?php
// check oracle database connection
if (!defined("ENVIRONMENT"))
define("ENVIRONMENT", "live");
$connection_string = "(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 3838))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = RAJAN)
))";
$oraConnection = oci_connect('username', 'password', $connection_string);
if (!$oraConnection) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
} else {
echo "Successfully connected to Oracle";
}
?>
Filed underWeb Developmentdatabase connectionoraclephp
Share

Rajan Dangi

Senior Web Developer

Senior web developer at SathiSoft. I write about PHP, Python, Linux and the practical details of building for the web.