Home  >  Article  >  Backend Development  >  How to Resolve Undefined Function Error oci_connect() When Connecting to Oracle Database with PHP?

How to Resolve Undefined Function Error oci_connect() When Connecting to Oracle Database with PHP?

DDD
DDDOriginal
2024-10-21 08:42:02764browse

How to Resolve Undefined Function Error oci_connect() When Connecting to Oracle Database with PHP?

Problem: Undefined Function Error with oci_connect()

When attempting to establish a PHP connection to an Oracle database, developers may encounter the following error:

Fatal error: Call to undefined function oci_connect()

Resolution:

This issue typically arises when the PHP Oracle extensions (OCI8) are not properly installed or configured. To resolve this problem, follow these steps:

  1. Ensure OCI Extensions Are Installed:

    • For Windows users, confirm that the php_oci8.dll or php_oci8_11g.dll extension files are present in your PHP ext directory (e.g., C:xamppphpext).
    • For Linux/Mac users, the OCI8 PECL package should be installed.
  2. Enable OCI Extensions:

    • In your php.ini file, uncomment and enable the following lines:

      • extension=php_oci8.dll (Windows)
      • extension=oci8.so (Linux/Mac)
  3. Configure Oracle Instant Client:

    • Download and install the appropriate version of Oracle Instant Client (11g or higher recommended).
    • Create a new environment variable named OCI_INCLUDE_DIR and point it to the Instant Client's include directory (e.g., C:oracleinstantclient_11_2sdkinclude).
    • Create another environment variable named OCI_LIBRARY_DIR and point it to the Instant Client's library directory (e.g., C:oracleinstantclient_11_2sdklib).
  4. Restart Apache Server:

    • Once the extensions and Oracle Instant Client are configured, restart your Apache server to apply the changes.
  5. Verify OCI8 Support:

    • In your PHP code, use phpinfo() to confirm that the OCI8 extension is loaded and properly configured.
  6. **Note:

    • Windows 64-bit systems may require the installation of a 32-bit version of Oracle Instant Client. Ensure that the environment variables are set accordingly for the 32-bit version.

The above is the detailed content of How to Resolve Undefined Function Error oci_connect() When Connecting to Oracle Database with PHP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn