How does php7.2 connect to oracle database? Installation of the OCI8 extension

How does php7.2 connect to oracle database? The following article will introduce to you the method of installing OCI8 extension to support oracle database in php7.2, I hope it will be helpful to you!

When working on a project, the remote oracle database provides us with an intermediate table. Some data in my business needs to be queried from this intermediate table in the oracle database.

PHP connects to oracle database. An extension to OCI8 is required. I am ashamed to say that I have worked for so many years and have not used the oracle database seriously.

The syntax of the mysql database is different from that of the oracle database. Don’t use the mysql syntax to operate the oracle database like me… a bit embarrassing…

Today we will roughly record the installation process of the OCI8 extension.

1: Download the file

1: Download address from oracle official website:

http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

Download the file (spotted the file name):

123oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm

: PHP official website download address:

https://www.php.net/manual/en/oci8.installation.php

PHP-OCI8 plugin

Download command:

1wget http://pecl.php.net/get/oci8-2.2.0.tgz

It is recommended to put the above three files in the /opt directory. Of course, it is your freedom to put them in the specific place. Just find it.

Two: installation

: Install the oracle plugin

12rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpmrpm -ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

May report an error:

ImportError: libaio.so.1: cannot open shared object file: No such file or directory”

The reason for the error has been given above, the libiao plugin is missing, the solution:

1yum install libaio

: Install the OCI8 plugin

(1): Unzip the tar package:

1tar -zxf oci8-2.2.0.tgz

(2): Enter the decompression directory

1cd oci8-2.2.0

(3): Run the following command:

1phpize

There may be an error when running: Can’t find PHP headers in /usr/include/php The php-devel package is required for use

solution

1yum install php72w-devel

(4): Use $ORACLE_HOME or Instant Client to configure the software package

1./configure --with-oci8=shared,instantclient,/usr/lib/oracle/<version>/client/lib

or

1./configure -with-oci8=shared,$ORACLE_HOME

(5): Execute compile and install:

1make install

There may be an error here:

make: *** No rule to make target build', needed by default’. Stop.

solution:

1: Install the following configuration:

1yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel

Reconfigure

1./configure

3: Compile

1make && make install

(6): Configure php.ini

We add in the PHP configuration file php.ini

1extension=oci8.so

Restart PHP

1systemctl restart php-fpm

Restart the web server (nginx, apache, etc.).

1systemctl restart nginx

Check it out PHPinfo();as shown below:

1.png

Then, you can configure multiple database links in your PHP framework.

Recommended study: ” PHP Video Tutorial “

The above is how php7.2 connects to oracle database? For more details on the installation of the OCI8 extension, please pay attention to other related articles on the php Chinese website!

Leave a Reply

Your email address will not be published.

en_USEnglish