`
aaron_ch
  • 浏览: 171908 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

PHP instantclient for oracle

    博客分类:
  • PHP
阅读更多

Oracle 10g Instant Client (free download available) is the easiest way for PHP to connect to a remote Oracle database, requiring installation of only three libraries.

The Instant Client libraries used by PHP access Oracle's current API, called OCI8. (This C interface takes its name from being first introduced in Oracle8.) PHP Oracle 8 Functions can call Oracle 8.1.7, 9.x, or 10.x directly, or optional abstraction classes like PEAR MDB2 and ADOdb can be used for convenience.

The older PHP "oracle" extension can also be used with Instant Client but it calls a deprecated Oracle API. New development with this extension is not recommended by the PHP community or by Oracle.

To use Instant Client with PHP 4 or 5 on Apache, follow the steps below. (See this section for details about 5.1.2 and its refactored OCI8 extension.) An existing Oracle database is needed; Instant Client does not include one.

Typically the database will be on another machine. If the database is local then Oracle components will generally already be available and Instant Client is not required.

Software Requirements:

Software Notes
Oracle Instant Client Download the "Instant Client Package - Basic." On Linux, also download the "Instant Client Package - SDK."
Apache HTTPD Server The PHP community still recommends Apache 1.3
PHP - PHP Hypertext Processor Version 4.3 or later

Enabling the PHP OCI8 Extension on Windows

The Instant Client binaries complement PHP's prebuilt binaries for Windows.

  1. Download the PHP binary zip file (not the installer build) and Apache. Install them following Installation on Windows Systems in the PHP Manual. OTN's PHP Developer Center contains links to useful background material such as "Installing Oracle, PHP, and Apache on Windows 2000/XP," which covers installation of a traditional, full Oracle 10g footprint (which is not required with Instant Client).

    Check that PHP is working before continuing. At this stage Oracle support is not enabled.

  2. Download the Instant Client Basic package for Windows from the Instant Client page on OTN. The zip file is about 30MB in size.

  3. Create a subdirectory (e.g., c:\instantclient10_1) and copy these libraries from the zip file:

    • oraociei10.dll
    • orannzsbb10.dll
    • oci.dll

    Collectively these three files are about 80MB in size.

    To use PHP's older "oracle" extension (enabled with "extension=php_oracle.dll" in php.ini), copy ociw32.dll instead of oci.dll.

  4. Edit the environment and add c:\instantclient10_1 to PATH before any other Oracle directories.

    For example, on Windows 2000, follow Start -> Settings -> Control Panel -> System -> Advanced -> Environment Variables and edit PATH in the System variables list.

    If a tnsnames.ora file is used to define Oracle Net service names, copy tnsnames.ora to c:\instantclient10_1 and set the user environment variable TNS_ADMIN to c:\instantclient10_1. A default service name can optionally be set in the user environment variable LOCAL.

    Set necessary Oracle globalization language environment variables such as NLS_LANG. If nothing is set, a default local environment will be assumed. See An Overview on Globalizing Oracle PHP Applications for more details.

    Unset unnecessary Oracle variables such as ORACLE_HOME and ORACLE_SID.

  5. Edit php.ini and uncomment the OCI8 extension:

    Set the extension_dir directive to the full PHP extension DLL path. In PHP 4 the DLLs are in the "extensions" sub-directory of the PHP software. In PHP 5 they are in "ext".

    extension=php_oci8.dll
    
  6. Restart Apache.

To check the extension is configured, create a simple PHP script phpinfo.php where the web server can read it.

Load the script into a browser using an "http://" URL. The browser page should contain an "oci8" section saying "OCI8 Support enabled".

<?php
  phpinfo();
?>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics