The steps for PHP to use PDO to access the oracle database are described in detail, pdooracle

Source: Internet
Author: User
Tags php and mysql

The steps for PHP to use PDO to access the oracle database are described in detail, pdooracle


From the very beginning, PDO learned from the success and failure of existing database expansion. Because the PDO code is brand new, we have the opportunity to design performance again to take advantage of the latest features of PHP 5.

PDO is designed to provide common database functions as the basis and provide convenient access to the unique functions of RDBMS.

Although PHP and Mysql in LAMP are standard pairs, the company's projects are Mysql and Oracle respectively as the Runtime Library and detailed single database, so PHP connection to the oracle database is also required. This article introduces how to use PDO to connect to the oracle database. Let's talk about it later.

Development Environment

First, describe the environment I used:

  • RedHat (CentOS) 6.7
  • PHP5.6
  • Oracle11g

For more information about php5.6, see here;

For how to install Oracle in linux, refer to here.

Of course, you can only install the instant client without installing the entire oracle. For the oracle connection steps of the instant client, see the final Thank-You section in this blog.

Before starting the following steps, make sure that the preceding three environments are correctly configured and available.

Install PDO_OCI

If you are installing php5.6.31, it seems that the pdo_oci module already comes with it. But to be secure, we will reinstall it.

Download and decompress

$ wget$ tar -xvf PDO_OCI-1.0.tgz$ cd PDO_OCI-1.0

Modify configuration file

Update the config. m4 file in the directory to adapt it to Oracle11g

# Locate the code similar to the following in line 3 and add the two lines: elif test-f $ PDO_OCI_DIR/lib/libclntsh. $ SHLIB_SUFFIX_NAME.11.2; then PDO_OCI_VERSION = 11.2 # Add the rows around 101st: 11.2) PHP_ADD_LIBRARY (clntsh, 1, PDO_OCI_SHARED_LIBADD );;



$ phpize

Phpize is similar to the gcc command and mainly used to generate a php plug-in module. Phpize depends on the php-deval module. If the command cannot be executed, install php-deval using yum;

You can run the following command to check whether the installation is successful:

$ rpm -qa | grep php

Check whether there is a If not, install the yum install php56w-deval.


After the phpize command is executed, many files will be generated under the directory, including configure and other standard files for installing the application through the source code in common linux. Execute the following commands in sequence:

$ ./configure$ make && make install

Here, we usually encounter a problem. When making, we will prompt you in the pdo_oci.c file:

pdo_oci.c:34: error: expected ‘=', ‘,', ‘;', ‘asm' or ‘attribute' before ‘pdo_oci_functions'

The solution is to modify row 34th of the pdo_oci.c file, change function_entry to zend_function_entry, and save and make again.

Create an INI File

After successful execution, you will be prompted that the module has been generated under the/usr/lib64/php/modules directory. What we need to do is to tell php that we want to reference this module.

Create an INI file pdo_oci.ini in the/etc/php. d directory. content:

Here, the pdo_oci module is installed. We can view it through php-m | grep oci.

Install OCI8

The next step is to install the oci8 module.

Download and decompress

Execute the following commands in the command line in sequence:

$ wget$ tar -xvf oci8-2.0.8.tgz$ cd oci8-2.0.8

Compile and install

The steps are similar to the above pdo_oci:

$ phpize$ ./configure --with-oci8=shared$ make && make install

Create an INI File

Similarly, we create oci8.ini in the/etc/php. d directory. content:

Restart Apache

Don't forget to restart the apache server to reload the php module:

$ service httpd restart

You can create a test. php file under the website directory. The content of the file is:


Then, go to the page to view the printed phpinfo information and view the pdo, pdo_oci, and oci8 modules.


The above is all the content of this article. I hope the content of this article has some reference and learning value for everyone's learning or work. If you have any questions, please leave a message to us, thank you for your support.

Reference & thanks

Php5.3 connect to the oracle client and install the pdo_oci Module

Installing PDO_OCI and OCI8 PHP extensions on CentOS 6.4 64bit

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.