PHP5.3 install php5.3pdo _ oci by connecting to the Oracle client and PDO_OCI module. PHP5.3 how to connect to the Oracle client and PDO_OCI module. php5.3pdo _ oci this article describes how to install PHP5.3 to connect to the Oracle client and PDO_OCI module. I would like to share with you the PHP5.3 installation method for connecting to the Oracle client and the PDO_OCI module, php5.3pdo _ oci
This example describes how to install PHP5.3 to connect to the Oracle client and the PDO_OCI module. We will share this with you for your reference. The details are as follows:
Although php is not the best partner in connecting to the oracle database, the development in the group does have such a requirement. If you do not refer to the appropriate documents, this process is still quite painful. 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. 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, run the following command to install it:
# 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
Assume that the web server uses apache.
1. install InstantClient
Instantclient is a simple client for oracle to connect to the database. you do not need to install a 500Moracle client to connect to the oracle Database. it is available in windows and linux versions. Select the desired version to download. you only need 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 32-bit soft link must be created for a 64-bit system. This may be a legacy bug, or problems may occur in subsequent compilation.
Next, let the system find the database file of the oracle client and modify LD_LIBRARY_PATH:
# vi /etc/profile.d/oracle.shexport ORACLE_HOME=/usr/lib/oracle/11.2/client64export LD_LIBRARY_PATH=$ORACLE_HOME/lib
Run source/etc/profile. d/oracle. sh to make the environment variable take effect.
2. install PDO_OCI
When connecting to the Internet, it is very simple to install php online via pecl. for details, refer to How to install oracle instantclient and pdo_oci on ubuntu machine.
Download the source PDO_OCI-1.0.tgz 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, you need to edit the config. m4 file in the ODI_OCI-1.0 folder below to make it support 11g:
# 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 );;
Compile and install pdo_oci extension: (after installation, 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/php. d/with the following content:
extension=pdo_oci.so
Verify that the installation is successful:
# Php-I | grep oci
If the following content is displayed, the installation is successful:
/Etc/php. d/pdo_oci.ini,
PDO drivers => oci, sqlite
Or
# php -m
3. install OCI8
Download the https://pecl.php.net/package/oci8 source file from the oci8-2.0.8.tgz.
# 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 an oci8.ini file under/etc/php. d/with the following content:
extension=oci8.so
Verify that the installation is successful:
# php -i|grep oci8/etc/php.d/oci8.ini,oci8oci8.connection_class => no value => no valueoci8.default_prefetch => 100 => 100oci8.events => Off => Offoci8.max_persistent => -1 => -1oci8.old_oci_close_semantics => Off => Offoci8.persistent_timeout => -1 => -1oci8.ping_interval => 60 => 60oci8.privileged_connect => Off => Offoci8.statement_cache_size => 20 => 20OLDPWD => /usr/local/src/oci8-2.0.8_SERVER["OLDPWD"] => /usr/local/src/oci8-2.0.8
Finally, do not forget to restart the anti-web server, such as apache. you can use phpinfo () to ensure that the extension is successfully installed.
4. test the connection
Create testoci. php 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 "
\n";while (($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) != false) { echo "
\n"; foreach ($row as $item) { echo "
".($item !== null ? htmlentities($item, ENT_QUOTES) : " ")." | \n"; } echo "
\n";}echo "
\n";?>
You can see the result when you access this page.