Quick Search:
Oracle PL/SQL Code Library
Find Or Post Oracle Jobs
Oracle Discussion & Chat
 Oracle PL/SQL: PHP and Oracle: Connect to database Jump to:  
Category: >> Oracle PL/SQL >> PHP and Oracle: Connect to database Bookmark and Share

<< lastnext >>

Snippet Name: PHP and Oracle: Connect to database

Description: To connect to Oracle from PHP scripts you'll need to use the oci8 extension (php_oci8.dll). If you installed PHP through your distribution's package management system this extension will most likely be available to you. To enable it, uncomment the following line in php.ini:

extension = php_oci8.dll

If you compiled PHP from source, you will have to reconfigure with the following option:


OCI (Oracle Call Interface) is the name of the driver we use to interact with Oracle. More information on the various options for php_oci8 is available on PHP's website.

The simple script shown to the right will make use of the driver.

Comment: (none)

Language: PHP, ORACLE
Highlight Mode: PHP
Last Modified: March 06th, 2009

$conn = ocilogon( "username", "password" );
$query = "SELECT title, author, ref_number, submit_date 
FROM test_table";
$parseresults = ociparse($conn, $query);
$rows = ocifetchstatement($parseresults, $rs);
<html><head><title>Simple PHP->OCI Script</title></head><body>
<center><table border=0 cellspacing='0' width='50%'><tr>
FOR ($iterate = 0; $iterate < $rows; $iterate++){
   ECHO "<tr>";
   ECHO "<td>" . $rs['author'][$iterate] . "</td>";
   ECHO "<td>" . $rs['title'][$iterate] . "</td>";
   ECHO "<td>" . $rs['submit_date'][$iterate] . "</td>";
   ECHO "</tr>";
ECHO "</table><br /><b>$rows recordswere found.</b></body></html>";

Oracle Magazine
and Oracle White Papers

SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 32 users online    © 2009 psoug.org

Forgot your password?