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()
Copy after login
Resolution:
This issue typically arises when the PHP Oracle extensions (OCI8) are not properly installed or configured. To resolve this problem, follow these steps:
-
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.
-
Enable OCI Extensions:
-
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).
-
Restart Apache Server:
- Once the extensions and Oracle Instant Client are configured, restart your Apache server to apply the changes.
-
Verify OCI8 Support:
- In your PHP code, use phpinfo() to confirm that the OCI8 extension is loaded and properly configured.
-
**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!