PHP5.3 Connect Oracle Client and Pdo_oci module installation method _php skills

Source: Internet
Author: User
Tags apache php install php

This example describes the installation method for PHP5.3 connecting Oracle clients and PDO_OCI modules. Share to everyone for your reference, specific as follows:

While PHP is not the best partner for connecting to Oracle databases, there is a real need for group development. If there is no reference to the appropriate document, the process is still very torture, the following is a record, the prototype is a foreign blog installing pdo_oci and OCI8 PHP extensions on CentOS 6.4 64bit.

Suppose you have installed the PHP environment, PHP version 5.3, to connect the Oracle server is 11g R2, operating system version CentOS 6.4 x86_64. If you do not have PHP installed, you can install it by using the following command:

# yum install php php-pdo # yum Install php-devel php-pear php-fpm php-gd php-ldap
\
php-mbstring php-xml PHP-XMLR PC php-zlib zlib-devel BC Libaio glibc

If the Web server uses Apache.

1. Install Instantclient

Instantclient is a simple client of Oracle's connection database that can connect to Oracle databases without installing a 500Moracle client, with Windows and Linux versions. Choose from here to download the version you need, just basic and devel two RPM packages.

Installation

# 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

Soft links

# 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

64-bit systems need to create 32-bit soft links, which may be a legacy bug, or the subsequent compilation will be problematic.

The next step is to enable the system to locate the Oracle client's library file and modify the Ld_library_path:

# vi/etc/profile.d/oracle.sh
export oracle_home=/usr/lib/oracle/11.2/client64
export ld_library_path=$ Oracle_home/lib

Execute source/etc/profile.d/oracle.sh to make the environment variable effective.

2. Install Pdo_oci

In the case of Internet connection, the PECL online installation of PHP extensions is very simple, refer to the How to install Oracle Instantclient and PDO_OCI on Ubuntu machine.

Download pdo_oci-1.0.tgz source files from Https://pecl.php.net/package/PDO_OCI.

# wget https://pecl.php.net/get/PDO_OCI-1.0.tgz
# TAR-XVF pdo_oci-1.0.tgz
# CD pdo_oci-1.0

Since Pdo_oci has not been updated for a long time, it is necessary to edit the Config.m4 file in the odi_oci-1.0 folder to support 11g:

# Find code similar to the following in line 10th, add these two lines:
elif test-f $PDO _oci_dir/lib/libclntsh. $SHLIB _suffix_name.11.2; then
 pdo_oci_ version=11.2
# Add these lines around line 101th:
11.2)
 php_add_library (clntsh, 1, Pdo_oci_shared_libadd)
 ;;

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

$ phpize
$/configure--with-pdo-oci=instantclient,/usr,11.2
$ make
$ sudo make install

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

Extension=pdo_oci.so

Verify that the installation was successful:

# Php-i|grep OCI

The installation succeeds when you see something like the following:

/etc/php.d/pdo_oci.ini,

PDO drivers => OCI, SQLite

Or

# php-m

3. Install OCI8

Download oci8-2.0.8.tgz source files from Https://pecl.php.net/package/oci8.

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

Compile installation oci8 extension:

# phpize #
/configure--with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib # make
# Make install

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

Extension=oci8.so

Verify that the installation was successful:

# php-i|grep Oci8
/etc/php.d/oci8.ini,
oci8 oci8.connection_class => No value
=> no value
Oci8.default_prefetch => => oci8.events => off => off oci8.max_persistent =>
-1 => -1
   oci8.old_oci_close_semantics => off => off
oci8.persistent_timeout =>-1 =>-1
oci8.ping_  Interval => =>
oci8.privileged_connect => off => off
oci8.statement_cache_size =>
oldpwd =>/usr/local/src/oci8-2.0.8
_server["oldpwd"] =>/usr/local/src/oci8-2.0.8

Finally, don't forget to reboot the reverse Web server such as Apache, and you can use Phpinfo () to ensure that the extension is installed successfully.

4. Test connection

Create testoci.php in your Web server, such as Apache PHP directory:

<?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? Htmlentities ($item, ent_quotes): "". </td>\n ";
  }
  echo "</tr>\n";
}
echo "</table>\n";
? >

Access to this page should be able to get the results.

More about PHP Interested readers can view the site topics: "PHP based on PDO Operation Database Skills Summary", "PHP+MONGODB Database Operation Skills Encyclopedia", "PHP object-oriented Programming Program Introduction", "PHP string (String) Usage Summary", " Introduction to PHP+MYSQL Database operations and a summary of PHP common database operations Tips

I hope this article will help you with the PHP program design.

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: info-contact@alibabacloud.com 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.