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

Both sides previous revisionPrevious revision
Next revision
Previous revision
classes:general:dbsamples:php_oracle [2017/01/14 19:41] localadminclasses:general:dbsamples:php_oracle [2017/01/14 19:44] (current) – [PHP Example Connection] localadmin
Line 2: Line 2:
  
 ===== students.cs.ndsu.nodak.edu ===== ===== students.cs.ndsu.nodak.edu =====
 +----
 The students.cs.ndsu.nodak.edu server still needs the Oracle driver installed and tested. 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.  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.1484444512.txt.gz · Last modified: by localadmin