Table of Contents
How to install PHP5.3 to connect to Oracle client and PDO_OCI module, php5.3pdo_oci
Home Backend Development PHP Tutorial How to connect PHP5.3 to Oracle client and install PDO_OCI module, php5.3pdo_oci_PHP tutorial

How to connect PHP5.3 to Oracle client and install PDO_OCI module, php5.3pdo_oci_PHP tutorial

Jul 12, 2016 am 08:51 AM
oracle pdo

How to install PHP5.3 to connect to Oracle client and PDO_OCI module, php5.3pdo_oci

This article describes the installation method of PHP5.3 to connect to Oracle client and PDO_OCI module. Share it with everyone for your reference, the details are as follows:

Although PHP is not the best partner to connect to the Oracle database, there is indeed such a need for in-group development. If you don’t refer to the appropriate documentation, this process is quite torturous. The following is a record. The prototype is a foreign blog Installing PDO_OCI and OCI8 PHP extensions on CentOS 6.4 64bit.

Assume that you have installed the PHP environment, the PHP version is 5.3, the Oracle server to be connected is 11g R2, and the operating system version is CentOS 6.4 x86_64. If php is not installed, you can install it with the following command:

1

2

3

# yum install php php-pdo

# yum install php-devel php-pear php-fpm php-gd php-ldap \

php-mbstring php-xml php-xmlrpc php- zlib zlib-devel bc libaio glibc

Copy after login

If the web server uses apache.

1. Install InstantClient

instantclient is a simple client for Oracle to connect to the database. You can connect to the Oracle database without installing a 500Moracle client. There are windows and Linux versions. Select the required version to download from here, only the Basic and Devel rpm packages are required.

Install

1

2

# rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm

# rpm -ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

Copy after login

Soft link

1

2

# ln -s /usr/include/oracle/11.2/client64 /usr/include/oracle/11.2/client

# ln -s /usr/lib/oracle/11.2/client64 /usr/lib/oracle/11.2/client

Copy after login

64-bit systems need to create 32-bit soft links. This may be a legacy bug, otherwise there will be problems with subsequent compilation.

The next step is to enable the system to find the Oracle client library file and modify LD_LIBRARY_PATH:

1

2

3

# vi /etc/profile.d/oracle.sh

export ORACLE_HOME=/usr/lib/oracle/11.2/client64

export LD_LIBRARY_PATH=$ORACLE_HOME/lib

Copy after login

Execute source /etc/profile.d/oracle.sh to make the environment variables take effect.

2. Install PDO_OCI

When connected to the Internet, it is very simple to install php extensions online through pecl. Please refer to How to install oracle instantclient and pdo_oci on ubuntu machine.

Download the PDO_OCI-1.0.tgz source file from https://pecl.php.net/package/PDO_OCI.

1

2

3

# wget https://pecl.php.net/get/PDO_OCI-1.0.tgz

# tar -xvf PDO_OCI-1.0.tgz

# cd PDO_OCI-1.0

Copy after login

Since PDO_OCI has not been updated for a long time, you need to edit the config.m4 file in the ODI_OCI-1.0 folder to make it support 11g:

1

2

3

4

5

6

7

# 在第10行左右找到与下面类似的代码,添加这两行:

elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.11.2; then

 PDO_OCI_VERSION=11.2

# 在第101行左右添加这几行:

11.2)

 PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD)

 ;;

Copy after login

Compile and install the pdo_oci extension: (This module can be found in /usr/lib64/php/modules/pdo_oci.so after the installation is complete)

1

2

3

4

$ phpize

$ ./configure --with-pdo-oci=instantclient,/usr,11.2

$ make

$ sudo make install

Copy after login

To enable this extension, create a new pdo_oci.ini file under /etc/php.d/, content:

1

extension=pdo_oci.so

Copy after login

Verify successful installation:

# php -i|grep oci

If you see content similar to the following, the installation is successful:

/etc/php.d/pdo_oci.ini,

1

PDO drivers => oci, sqlite

Copy after login

or

1

# php -m

Copy after login

3. Install OCI8

Download the oci8-2.0.8.tgz source file from https://pecl.php.net/package/oci8.

1

2

3

# wget https://pecl.php.net/get/oci8-2.0.8.tgz

# tar -xvf oci8-2.0.8.tgz

# cd oci8-2.0.8

Copy after login

Compile and install oci8 extension:

1

2

3

4

# phpize

# ./configure --with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib

# make

# make install

Copy after login

To enable this extension, create a new oci8.ini file under /etc/php.d/, content:

1

extension=oci8.so

Copy after login

Verify successful installation:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

# php -i|grep oci8

/etc/php.d/oci8.ini,

oci8

oci8.connection_class => no value => no value

oci8.default_prefetch => 100 => 100

oci8.events => Off => Off

oci8.max_persistent => -1 => -1

oci8.old_oci_close_semantics => Off => Off

oci8.persistent_timeout => -1 => -1

oci8.ping_interval => 60 => 60

oci8.privileged_connect => Off => Off

oci8.statement_cache_size => 20 => 20

OLDPWD => /usr/local/src/oci8-2.0.8

_SERVER["OLDPWD"] => /usr/local/src/oci8-2.0.8

Copy after login

Finally, don’t forget to restart the reverse web server such as apache. You can use phpinfo() to ensure whether the extension is successfully installed.

4. Test connection

Create testoci.php in the php directory of your web server such as apache:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

<&#63;php

$conn = oci_connect('username', 'password', '172.29.88.178/DBTEST');

$stid = oci_parse($conn, 'select table_name from user_tables');

oci_execute($stid);

echo "<table>\n";

while (($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {

  echo "<tr>\n";

  foreach ($row as $item) {

    echo " <td>".($item !== null &#63; htmlentities($item, ENT_QUOTES) : " ")."</td>\n";

  }

  echo "</tr>\n";

}

echo "</table>\n";

&#63;>

Copy after login

You should get the results by visiting this page.

Readers who are interested in more PHP-related content can check out the special topics of this site: "Summary of PHP database operation skills based on pdo", "PHP MongoDB database operation skills collection", "php object-oriented programming introductory tutorial", "php Summary of String Usage", "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of PHP Common Database Operation Skills"

I hope this article will be helpful to everyone in PHP programming.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1127916.htmlTechArticleHow to install PHP5.3 to connect to Oracle client and PDO_OCI module, php5.3pdo_oci This article describes PHP5.3 with examples How to connect Oracle client and PDO_OCI module installation method. Share it with everyone for your reference...
Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

How to delete all data from oracle How to delete all data from oracle Apr 11, 2025 pm 08:36 PM

Deleting all data in Oracle requires the following steps: 1. Establish a connection; 2. Disable foreign key constraints; 3. Delete table data; 4. Submit transactions; 5. Enable foreign key constraints (optional). Be sure to back up the database before execution to prevent data loss.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to paginate oracle database How to paginate oracle database Apr 11, 2025 pm 08:42 PM

Oracle database paging uses ROWNUM pseudo-columns or FETCH statements to implement: ROWNUM pseudo-columns are used to filter results by row numbers and are suitable for complex queries. The FETCH statement is used to get the specified number of first rows and is suitable for simple queries.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

How to open a database in oracle How to open a database in oracle Apr 11, 2025 pm 10:51 PM

The steps to open an Oracle database are as follows: Open the Oracle database client and connect to the database server: connect username/password@servername Use the SQLPLUS command to open the database: SQLPLUS

See all articles