Search the Site


bottom corner

Connecting from PHP to an Oracle database

This article demonstrates how to connect to an Oracle database from PHP.

This page is filed under keyword(s): php, oracle.

This article assumes that your "tnsnames.ora" file has already been configured. For the propose of this article, we will assume that the TNS entry we are attempting to connect to is called "oradb".

// Database connection
$conn = oci_connect("scott", "tiger", "oradb");
if (!$conn) {
   $m = oci_error();
   trigger_error(htmlentities($m["message"], ENT_QUOTES), E_USER_ERROR);

// Perform a sample query
$sql = oci_parse($conn, "select user from dual");
while (($row = oci_fetch_array($sql))){

// Close the connection

Did you find this page useful? Please consider browsing other articles or subscribing to the RSS feed to keep up with latest.

This page is filed under keyword(s): php, oracle.
Author: C. Peter Chen
Last updated: 26 Nov 2014

bottom corner