This article describes the installation method of PHP5.3 connecting Oracle client and PDO_OCI module. Share it for your reference, as follows:
Although php connection to oracle database is not the best partner, there is indeed such a requirement for in-group development. If you don't refer to the appropriate documents, this process is quite tormenting. Below is a record, and the prototype is a foreign blogInstalling PDO_OCI and OCI8 PHP extensions on CentOS 6.4 64bit 。
Suppose you have installed the PHP environment, the PHP version is 5.3, the oracle server you want to connect to is 11g R2, and the operating system version is CentOS 6.4 x86_64. If you do not have php installed, you can install it through 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- zlib zlib-devel bc libaio glibc
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. It has Windows and Linux versions. From here, select the version you want to download, just need the two rpm packages Basic and Devel.
Install
# 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 link
# 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. This may be a legacy bug, and there will be problems with the compilation.
Next, we need to enable the system to find the library files of the oracle client and modify LD_LIBRARY_PATH:
# vi /etc// export ORACLE_HOME=/usr/lib/oracle/11.2/client64 export LD_LIBRARY_PATH=$ORACLE_HOME/lib
Execute source /etc// to make the environment variable take effect.
2. Install PDO_OCI
With the internet connection, it is very simple to install php extensions online through pecl, refer to How to install oracle instantclient and pdo_oci on ubuntu machine.
from/package/PDO_OCIDownload PDO_OCI-1. Source file.
# wget /get/PDO_OCI-1. # tar -xvf PDO_OCI-1. # cd PDO_OCI-1.0
Since PDO_OCI has not been updated for a long time, the following is to edit the config.m4 file in the ODI_OCI-1.0 folder to make it support 11g:
# Find the code similar to the following around line 10 and 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 101:11.2) PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD) ;;
Compile and install the pdo_oci extension: (After the installation is completed, you can find this module in /usr/lib64/php/modules/pdo_oci.so)
$ 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//, with contents:
extension=pdo_oci.so
Verify that the installation is successful:
# php -i|grep oci
After seeing something like the following, the installation was successful:
/etc//pdo_oci.ini,
PDO drivers => oci, sqlite
or
# php -m
3. Install OCI8
from/package/oci8 Download the oci8-2.0. source file.
# wget /get/oci8-2.0. # tar -xvf oci8-2.0. # 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 file under /etc//, with contents:
extension=
Verify that the installation is successful:
# php -i|grep oci8 /etc//, oci8 oci8.connection_class => no value => no value oci8.default_prefetch => 100 => 100 => 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
Finally, don’t forget to restart the reverse web server such as apache. You can use phpinfo() to ensure that the extension is successfully installed.
4. Test the connection
Create in the php directory of your web server such as apache:
<?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"; ?>
Visit this page to get results.
For more information about PHP related content, please check out the topic of this site:Summary of PHP's skills to operate database based on pdo》、《Complete collection of PHP+MongoDB database operation skills》、《PHP object-oriented programming tutorial》、《Summary of usage of php strings》、《PHP+mysql database operation tutorial"and"Summary of common database operation techniques for php》
I hope this article will be helpful to everyone's PHP programming.