User Tools

Site Tools


classes:general:dbsamples:php_oracle

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
classes:general:dbsamples:php_oracle [2017/01/15 01:41] – created localadminclasses:general:dbsamples:php_oracle [2017/01/15 01:44] (current) – [PHP Example Connection] localadmin
Line 1: Line 1:
 ====== Using the Oracle driver in PHP ====== ====== 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. 
 +
 +<code>
 +<?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);
 +
 +?>
 +
 +</code>
  
  
classes/general/dbsamples/php_oracle.1484444479.txt.gz · Last modified: by localadmin