search
HomeBackend DevelopmentPHP TutorialHow to connect PHP5.3 to Oracle client and install PDO_OCI module, php5.3pdo_oci_PHP tutorial

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:

# 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. There are windows and Linux versions. Select the required version to download from here, only the Basic and Devel rpm packages are required.

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

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:

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

# 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 to make it support 11g:

# 在第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)
 ;;

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)

$ 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 successful installation:

# php -i|grep oci

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

/etc/php.d/pdo_oci.ini,

PDO drivers => oci, sqlite

or

# php -m

3. Install 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 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 successful installation:

# 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

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:

<&#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;>

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
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
PHP's Purpose: Building Dynamic WebsitesPHP's Purpose: Building Dynamic WebsitesApr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP: Handling Databases and Server-Side LogicPHP: Handling Databases and Server-Side LogicApr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

How do you prevent SQL Injection in PHP? (Prepared statements, PDO)How do you prevent SQL Injection in PHP? (Prepared statements, PDO)Apr 15, 2025 am 12:15 AM

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

PHP and Python: Code Examples and ComparisonPHP and Python: Code Examples and ComparisonApr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP in Action: Real-World Examples and ApplicationsPHP in Action: Real-World Examples and ApplicationsApr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: Creating Interactive Web Content with EasePHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AM

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python: Comparing Two Popular Programming LanguagesPHP and Python: Comparing Two Popular Programming LanguagesApr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

The Enduring Relevance of PHP: Is It Still Alive?The Enduring Relevance of PHP: Is It Still Alive?Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download

Atom editor mac version download

The most popular open source editor