Connecting to Oracle via php

April 2018

Oracle database is a useful database server which can be connected through a PHP script. Web servers using SQLPlus can access the Oracle server through this process. Servers based on the Oracle 8i module can normally be connected. For PHP to interact with the Oracle database, the PHP scripting language must be assembled to this extension module. On the Windows OS, the php.ini file must be edited before the process is accomplished.


Below is an article based on an example of connection to an Oracle database through a php script. However it is not designed to configure your oracle server and oracle client. It ensures that you can access your oracle server from the web server using the SQLPlus.
We can normally connect to a server based on Oracle 8i.


It is essential to assemble PHP with Oracle8i module. Under windows, it is crucial to the php.ini to include the line extension=php_oci8.dll

Example of code

$c1 = ocilogon("scott", "tiger", $db);      
$c2 = ocilogon("scott", "tiger", $db);      

function create_table($conn)       

  $stmt = ociparse($conn, "create table scott.hallo (test varchar2(64))");      
  echo $conn . " created table\n\n";      

function drop_table($conn)       

  $stmt = ociparse($conn, "drop table scott.hallo");      
  echo $conn . " dropped table\n\n";      

function insert_data($conn)       

  $stmt = ociparse($conn, "insert into scott.hallo       
           values('$conn' || ' ' || to_char(sysdate,'DD-MON-YY HH24:MI:SS'))");      
  ociexecute($stmt, OCI_DEFAULT);      
  echo $conn . " inserted hallo\n\n";

This is one of the easiest way to access Oracle amongst others.
Published by deri58. Latest update on November 22, 2011 at 05:33 PM by Rik Sharma.
This document, titled "Connecting to Oracle via php," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (
How to easily display PHP/HTML codes in your webpages
Connecting to an Ingres database with PHP