User Tools

Site Tools


classes:general:dbsamples:php_oracle

Using the Oracle driver in PHP

students.cs.ndsu.nodak.edu


The students.cs.ndsu.nodak.edu server still needs the Oracle driver installed and tested.

Once it is operational, the code to use it is a bit different from the same code in Java.

PHP Example Connection

Here is a small example to connect to the Oracle database from PHP, be sure to replace 'username', 'password' and 'query' with your own.

<?php

// The connection string is loooooooong. It's easiest to copy/paste this line. Remember to replace 'username' and 'password'!
$conn = oci_connect('username', 'password', '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(Host=db1.chpc.ndsu.nodak.edu)(Port=1521)))(CONNECT_DATA=(SID=cs)))');

// Put your query in here
$query = '';

$stid = oci_parse($conn,$query);
oci_execute($stid,OCI_DEFAULT);

// Iterate through each row
while ($row = oci_fetch_array($stid,OCI_ASSOC)) 
{
   // Iterate through each item in the row and echo it
   foreach ($row as $item) 
   {
      echo $item.' '; 
   }
   echo '<br/>';
}
oci_free_statement($stid);
oci_close($conn);

?>
classes/general/dbsamples/php_oracle.txt · Last modified: 2017/01/14 19:44 by localadmin