PHP5.3 connecting the installation methods of Oracle client and PDO_OCI module, php5.3pdo_oci_php tutorial

Source: Internet
Author: User
Tags php online

PHP5.3 connect the installation method of Oracle client and PDO_OCI module, PHP5.3PDO_OCI


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

PHP connection to Oracle database is not the best partner, but there is a real need for in-group development. If it's not the right documentation, the process is pretty grueling, and here's a record that the prototype is a foreign blog installing pdo_oci and OCI8 PHP extensions on CentOS 6.4 64bit.

Assuming you have installed PHP environment, PHP version 5.3, to connect to 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-xmlrpc Php-zl IB zlib-devel BC Libaio glibc

If the Web server uses Apache.

1. Installing Instantclient

Instantclient is a simple client of Oracle's connected database and can connect to an Oracle database with Windows and Linux versions without installing a 500Moracle client. Select the desired version from here for download, 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

A 64-bit system needs to create a 32-bit soft link, which may be a legacy bug, or the subsequent compilation will be problematic.

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

# vi/etc/profile.d/oracle.shexport Oracle_home=/usr/lib/oracle/11.2/client64export LD_LIBRARY_PATH= $ORACLE _home/ Lib

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

2. Installing PDO_OCI

In the case of Internet connection, the extension to install PHP online via pecl is very simple, see how to install the Oracle Instantclient and PDO_OCI on the Ubuntu machine.

Download the pdo_oci-1.0.tgz source file 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, the following need to edit the Config.m4 file in the odi_oci-1.0 folder to allow it to support 11g:

# Find code similar to the following on 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/, with the following contents:

Extension=pdo_oci.so

Verify that the installation was successful:

# Php-i|grep OCI

The installation succeeds if you see something like the following:

/etc/php.d/pdo_oci.ini,

PDO drivers = OCI, SQLite

Or

# php-m

3. Installing OCI8

Download the oci8-2.0.8.tgz source file 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 and install the 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/, with the following contents:

Extension=oci8.so

Verify that the installation was successful:

# Php-i|grep Oci8/etc/php.d/oci8.ini,oci8oci8.connection_class = no value = no Valueoci8.default_prefetch = 100oci8.events = = Off = Offoci8.max_persistent = 1 = -1oci8.old_oci_close_semantics = off =& Gt Offoci8.persistent_timeout = 1 = -1oci8.ping_interval = 60oci8.privileged_connect = Off = = Foci8.statement_cache_size = 20OLDPWD =/usr/local/src/oci8-2.0.8_server["oldpwd"] =/usr/local/ src/oci8-2.0.8

Finally, don't forget to restart the reverse Web server, such as Apache, by Phpinfo () to ensure that the extension is installed successfully.

4. Test the connection

Create testoci.php in your Web server like Apache's 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 "
 
  
  
   
   
  \ n ($row = Oci_fetch_array ($stid, oci_assoc+oci_return_nulls)) = = False) {echo]  
  
   
   
      \ n "; foreach ($row as $item) { echo ' 
     \ n "; } echo " 
    \ n ";} echo " 
   
". ($item!== null? htmlentities ($item, ent_quotes): ""). "
\ n ";? >

Visit this page and you should be able to get the results.

More interested in PHP related content readers can view this site topic: "PHP based on PDO operation database Tips Summary", "PHP+MONGODB Database operation Skills Daquan", "PHP Object-oriented Programming tutorial", "PHP String Usage Summary", " Php+mysql database Operation Tutorial "and" PHP common database Operation Skills Summary "

I hope this article is helpful to you in PHP programming.

http://www.bkjia.com/PHPjc/1127916.html www.bkjia.com true http://www.bkjia.com/PHPjc/1127916.html techarticle PHP5.3 Connect the installation method of Oracle client and PDO_OCI module, PHP5.3PDO_OCI This example describes the installation method of PHP5.3 connecting Oracle client and PDO_OCI module. Share for everyone to join us ...

  • 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.