oracle connectivity with php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yasir_memon
Forum Commoner
Posts: 48
Joined: Tue Aug 11, 2009 12:29 am

oracle connectivity with php

Post by yasir_memon »

can any one please tell me the simple coding for connecting oracle database??

waiting for ur replies
thanks in advance
User avatar
turbolemon
Forum Commoner
Posts: 70
Joined: Tue Jul 14, 2009 6:45 am
Location: Preston, UK

Re: oracle connectivity with php

Post by turbolemon »

You could use Oracle's OCI module, or PDO_OCI:

http://uk.php.net/oci8
http://us.php.net/manual/en/ref.pdo-oci.php

From the Oracle wiki:
http://wiki.oracle.com/page/PHP+Oracle+FAQ wrote:<?php

$conn = oci_connect('myusername', 'mypassword', 'myhost/XE');

if (!$conn) {
trigger_error("Could not connect to database", E_USER_ERROR);
}

?>
yasir_memon
Forum Commoner
Posts: 48
Joined: Tue Aug 11, 2009 12:29 am

Re: oracle connectivity with php

Post by yasir_memon »

thx for ur repy when i am using this code this error is occured "could not find driver" can u please tell me why this is happening
thanks
User avatar
turbolemon
Forum Commoner
Posts: 70
Joined: Tue Jul 14, 2009 6:45 am
Location: Preston, UK

Re: oracle connectivity with php

Post by turbolemon »

You need the OCI driver module installed in PHP. This means that you need to have install the oracle "instant client" binary on your server system. Then you need to install the php module, which is really easy if you have PEAR.

http://ubuntuforums.org/archive/index.php/t-92528.html

This link describes how to install OCI / Instant Client on Ubuntu/Debian systems, though the post is quite old! It just depends on your access to the server config and operating system really.
yasir_memon
Forum Commoner
Posts: 48
Joined: Tue Aug 11, 2009 12:29 am

Re: oracle connectivity with php

Post by yasir_memon »

i am still facing problems can u please tell me the steps how to connect with oracle database i am using windows server 2003 and wamp software

waiting for ur replies

thanks
User avatar
turbolemon
Forum Commoner
Posts: 70
Joined: Tue Jul 14, 2009 6:45 am
Location: Preston, UK

Re: oracle connectivity with php

Post by turbolemon »

I have never personally undertaken the task, certainly not under windows. Try calling phpinfo() to check if the OCI8 module is already installed, and if so you just need to install http://www.oracle.com/technology/softwa ... index.html for your platform.

This is the official walk-through, should be fairly straight forward http://www.oracle.com/technology/pub/no ... stant.html. Instead of going away and installing a fresh Apache/PHP you should be able to go ahead and modify your existing installation, adding the DLL to the relevant directory and adding the line to php.ini to load the module.

Thats the best I can offer!
yasir_memon
Forum Commoner
Posts: 48
Joined: Tue Aug 11, 2009 12:29 am

Re: oracle connectivity with php

Post by yasir_memon »

i want to connect with oracle data base when im using this code i am facing this error
could not find driver

$tns = "
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.0.2)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = aktmapp)
)
)
";
$db_username = "ERP_TEST";
$db_password = "ERP_TEST";
try{
$conn = new PDO("oci:dbname=".$tns,$db_username,$db_password);
}catch(PDOException $e){
echo ($e->getMessage());
}


and when i am using this code i am facing this error
Fatal error: Call to undefined function oci_connect() in C:\wamp\www\conn.php on line 17

so kindly tell me what type of mistake is there waiting for rplies thx


$tnsName = '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.0.2)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = aktmapp)
)
)';


$username = 'ERP_TEST';
$password = 'ERP_TEST';

//$conn=oci_connect()
$conn=oci_connect($username,$password,'//172.16.0.2:1521/XE');

if (!$conn) {
$e = oci_error(); // For oci_connect errors pass no handle
echo '<b><font color="red">FAILED</font></b> : ' . htmlentities($e[
'message']);
} else {
echo '<b><font color="green">OK!</font></b>';
oci_close($conn);
Post Reply