Php Flow » Php

Connect PHP with Oracle

PHP is emerging web technology in this era.The main features of PHP is free to use and easy to understand.Oracle is most popular DB in world,so normally we are using mysql connectivity with php but sometimes we need to add connectivity oracle with php. In this tutorial i will describe how to connect you application with oracle database.
oracle-with-php

There are following steps to need connect oracle with PHP.
Step 1: We need host,username, password and port for connectivity.

1
2
3
4
5
6
7
8
$oracleConnect = NULL;

$db_test = '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=portnumber)) (CONNECT_DATA=(SID=dbi_subroutine)))';
$oracleConnect = oci_connect("username", "pass", $db_test)
if (!$oracleConnect) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

Step 2: Now we will use above connection object and fire SQL.

1
2
3
4
5
6
7
8
<?php
$sql = "select name from user order by PES.NAME";
$rs = oci_parse($oracleConnect, $sql);
oci_execute($rs);
while ($row = oci_fetch_array($rs, OCI_ASSOC+OCI_RETURN_NULLS)) {
	    echo '<pre>'; print_r($row); echo '</pre>';
}
oci_free_statement($rs);

I hope its helps to you.

Did you enjoy this article? Share it!

About the Author:

Hi, This is Parvez Alam from India. I am software developer with 4 years’ experience in web development. I have submitted articles on PHP, Mysql, Magento,CSS, HTML, jQuery, web designing and social API. You can subscribe to my blog via RSS/Twitter/Google plus and Facebook. parvez1487(at)gmail(dot)com

Random Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>