?
Solved

Connecting To an Oracle DB with PHP

Posted on 2009-07-08
6
Medium Priority
?
743 Views
Last Modified: 2013-12-13
Hello,

I'm trying to connect to a oracle database using PHP.  I have already enable the extension OCI8 and tried to connect. However when I try to connect I get the error message:


Fatal error: Call to undefined function oci_connect() in C:\wamp\www\test\connection2.php on line 15

Below is the code I'm using to connect. For some reason, i think Its not recognizing the OCI. If anyone see anything wrong with my code please let me know thanks.
$c = oci_connect("username","password","localhost/xe");

Open in new window

0
Comment
Question by:Robert Thomas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 9

Expert Comment

by:Sander Stad
ID: 24811952
Are you sure you enabled the Oracle extension. Can you try do get the results from phpinfo() from your server?

To do this:
- Create a new php file
- Put in the code below
- Open the php file through your webserver in a brwoser



<?php
 
phpinfo();
 
?>

Open in new window

0
 
LVL 9

Expert Comment

by:Sander Stad
ID: 24811987
If it is enabled you should get something like:

OCI8 Support => enabled
 Version => 1.2.4
 Revision => $Revision: 1.269.2.16.2.38 $
 Active Persistent Connections => 0
 Active Connections => 0
 Oracle Version => 10.1
 Compile-time ORACLE_HOME => /ORACLE/app/oracle/product/client
 Libraries Used =>
 Temporary Lob support => enabled
 Collections support => enabled

If it's not enabled you should check if you've edited the right php.ini file.

If everything is ok try the code below to create a testpage to see if the connection succeeds.
I see that you're using "localhost/xe" in your connection. Try to use the local ip address "127.0.0.1" to connect. Windows might create problem by using the value "localhost".

<?php
if ($conn = oci_connect('hr', 'hr', '//127.0.0.1:1521/xe')) {
  print 'Successfully connected to Oracle Database XE!';
  oci_close($conn);
} else {
  $errmsg = oci_error();
  print 'Oracle connect error: ' . $errmsg;
}
?>

Open in new window

0
 

Author Comment

by:Robert Thomas
ID: 24816098
I think I properly enable oci8. But its not showing on the information page. I went into the php.ini file and enable it in the the extension area by taking away the ";".  But I just found the OCI8 section below. Probably a stupid question, but do I need to un-comment and enable all the scripts in that section?
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 9

Expert Comment

by:Sander Stad
ID: 24820627
If the extension is not showing on the info page than you did not enable it. You probably have multiple php.ini  files.
Can you search your server/computer for the php.ini files.

If you want to set different settings like max connection etc then you can enable th settints in the OCI8 section.
0
 

Author Comment

by:Robert Thomas
ID: 24836989
I've checked there appears to be only one.  The only place oci8 appears in the php info in the configure command:

cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack" "--with-pdo-oci=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8=C:\php-sdk\oracle\instantclient10\sdk,shared"

Is there any possible way that the extension could be blocked by another extention?
0
 

Accepted Solution

by:
Robert Thomas earned 0 total points
ID: 24892352
I had to edit the the system path and install the system client before the oci8 extension could be used.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question