简体   繁体   中英

Connecting to Oracle using PHP

How do I connect to a remote Oracle database instance from PHP?

I need to query (read only) the remote Oracle database for some information; do I need to have an Oracle Instant Client installed?

Is the OCI extension for PHP enough?

From PHP Manual

  • You will need the Oracle client libraries to use this extension.

  • The most convenient way to install all the required files is to use Oracle Instant Client, which is available from Oracle's site

The best manual for using PHP with Oracle is Underground PHP Oracle Manual . Periodically updated. For example last update describe new cool OCI (Oracle Call Interface) features. I found it by accident and since then has never regretted. Start from that good manual.

there are a couple of steps you need to go through to make this work.

First, you need to install the oracle driver for whatever OS you have. Then, create a DSN for odbc to use to connect the php function call to the oracle database. On windows, you can find this on the Control Panel -> ODBC Sources

Once you have done this, restart the DB, the web server and then you should be able to test it all with this:

odbc_connect($dsn,$user,$pass);

If you have linux, the same steps are needed but I'm not sure how you create a DSN in unix.

If you're attempting to connect to oracle on ubuntu with PHP, the following links have been more than helpful:

A) http://pecl.php.net/bugs/bug.php?id=9253

That's the real-workhorse one - it gives you just about all the data you need.

B) http://fabrizioballiano.net/2008/01/26/how-to-install-php-pdo_oci-on-ubuntu-gutsy/

This is also helpful for details of things that need to be installed for oracle to work with ubuntu.

If you're using it with PHP, you'll need to make sure that the TNS_ADMIN and ORACLE_HOME environment variables are available for apache's user - there's a file named 'envvars' in the apache2 directory where you can set these. (For my own ease of use, I have the two point to the same directory.)

I saw this in the "Notes" section of the PHP documentation :

If you're using PHP with Oracle Instant Client, you can use easy connect naming method (...)

So I think it's rather clear that you can connect to an Oracle DB without the Oracle Instant Client, using only the PHP Oracle extension.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM