Home  >  Article  >  Backend Development  >  How to connect php to oracle database and simple analysis

How to connect php to oracle database and simple analysis

墨辰丷
墨辰丷Original
2018-06-02 10:06:164095browse

This article mainly introduces the method of connecting PHP to the Oracle database, briefly analyzes the common methods and specific operating techniques of PHP connecting to the Oracle database, and summarizes and analyzes possible problems. Friends in need can refer to it

This article briefly analyzes the method of connecting PHP to the Oracle database. Share it with everyone for your reference, the details are as follows:

PHP provides two sets of functions to connect to Oracle, namely ORA_ and OCI functions. The ORA_ function is slightly outdated. The OCI function update is said to be better. The usage syntax of the two is almost the same. Your PHP installation options should support the use of both.

Since OCI functions need to use Oracle8 Call-Interface (OCI8) to access databases above oracle8, this extension module requires the client function library of oracle8, so if you need to connect to a remote database, you also need a connection end To install the Oracle client software, you can download it for free from http://www.oracle.com. This is necessary, otherwise an undefined method error will be reported.

Steps:

1. Install apache and php.
2. Install Oracle 10g Instant Client (or other versions).
2. Open the extension=php_oci8 extension in php.ini.
3. Copy the php_oci8.dll file in the php/ext directory to the system32 directory.
4. Write test scripts for testing.

<?php
$conn = oci_connect(&#39;用户名&#39;, &#39;密码&#39;, &#39;远程数据库名(eg.//192.168.1.133/orcl)&#39;);
if (!$conn) {
  $e = oci_error();
  print htmlentities($e[&#39;message&#39;]);
  exit;
}else {
  echo "连接oracle成功!";
}
?>

Possible errors:

1. call to undefined function oci_connect()...: This is because php_oci8.dll was not found, check You may see the error log error.log of apache: php startup:unable to load dynamic liberaries php_oci8.dll......

Solution:Change the php/ext directory Copy the php_oci8.dll file to the system32 directory. If it still doesn't work, copy the oci.dll file in the /product/10.2.0/db_2/BIN directory under the Oracle 10g Instant Client installation directory to the system32 directory.

2. OCIEnvNlsCreate() failed.... PATH includes the directory with Oracle Instant Client libraries

Solution: Restart the machine, if it still doesn't work, Install Oracle 10g Instant Client.

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

phpDetailed explanation of WeChat development access example

PHP MySQL implements fuzzy query of employee information Function

Summary of three commonly used design patterns in PHP

The above is the detailed content of How to connect php to oracle database and simple analysis. 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