In Linux, PHP supports oracle, installing oracle instant client, pdo_oci notes

Source: Internet
Author: User
Tags php source code web services port number oracle database

Installation


First of all, PHP supports oracle. The first thing I think of is the pdo-related driver. After reading it, it is actually called pdo_oci.

 

But it still depends on the oracle instant client, which needs to be downloaded from the oracle official website:

Http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

 

Select the corresponding system version, click in, here I am 64-bit linux, so choose Instant Client for Linux x86-64, will let you agree to a protocol, called Accept License Agreement, you can download it after selecting this option.

 

It is worth mentioning that if you want to download through wget, you need to register an oracle account and log in, and then click download on your computer first, get an actual url (including a token) and copy the url to wget on the server. The url in the wget webpage cannot be obtained directly. Remember.

 

You need to download two packages:

Oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm

Oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm

 

The version number may be different. Check the keywords: basic and devel.

 

These two packages are downloaded to the server and installed separately:

Rpm-ivh oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
Rpm-ivh oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm


Because it is a 64-bit system, to prevent php compilation expansion problems, make a soft connection between the two directories that have just been installed.

Ln-s/usr/lib/oracle/12.1/client64/usr/lib/oracle/12.1/client
Ln-s/usr/include/oracle/12.1/client64/usr/include/oracle/12.1/client
OK. Next, install the pdo_oci extension.

 

First, you should have a php source code. If not, please download a corresponding version from the official website.

Assume that my source code is in/home/src/php56

Cd/home/src/php56
Cd ext/pdo_oci
Phpize # Note: If you do not have this command, find the bin/in the php installation directory, for example,/usr/local/php/bin/phpize.
./Configure -- with-pdo-oci = instantclient,/usr, 12.1 -- with-php-config =/usr/bin/php-config
# Note: 12.1 must correspond to the version number of the oracle instant installed above. It is the same as the number in oracle/12.1. -- with-php-config is the same as phpize, in the bin directory of the php installation directory, you need to change the two to your actual situation.
Make & make install
If the compilation succeeds, modify php. ini and leave two blank lines at the end of the file.

Extension = pdo_oci.so;
Okay, pass

Php-m
Command to see if there is any PDO_OCI line, if there is, it is OK.

For web services, restart apache or php-fpm.

 

Usage
The usage process is similar to that of pdo. I don't know much about oracle, but I also encountered a fault, that is, I cannot connect to oracle.

First, use the following method to connect:

$ Pdh = new PDO ('oci: dbname = IP Address: Port number/SID ', user name, password );
Error:

SQLSTATE [HY000]: pdo_oci_handle_factory: ORA-12514: TNS: listener does not currently know of service requested in connect descriptor
Later, I found the answer on statckoverflow and changed it to the following connection method:

$ Tns ="
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST = your IP) (PORT = PORT number ))
    )
(CONNECT_DATA =
(SID = the SID of your oracle database)
    )
  )
";
$ Db_username = "youname ";
$ Db_password = "yourpassword ";
Try {
$ Conn = new PDO ("oci: dbname =". $ tns, $ db_username, $ db_password );
} Catch (PDOException $ e ){
Echo ($ e-> getMessage ());
}
So there is no problem.

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.