Extended Oracle Function Library (OCI) _php instance in Wamp environment

Source: Internet
Author: User
Tags oracle database

My colleague received a task yesterday to process the contents of the Oracle database in PHP, but the PHP open Oracle extension is not as straightforward as MySQL, and requires a little something to open it.

The first step is to have the official Oracle download a install client package, under win to find your corresponding system version of the ZIP (note that this is the system version)

As of 2015-06-25, the download address is as follows http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

For example, select Instant Client for Microsoft Windows (x64) because PHP is extended OCI, you must choose the version of the most complete, no other oci, download may need to have an account, verification can be downloaded, Directly with the connection to download is not good, no words to register a bit better

In the second part, you need to download the extension package in the win system, which is the. dll file download address http://pecl.php.net/package/oci8 the next piece of crap is telling you how to find it.

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

Official Instant Client site. Pull to the last Related Developer Centers inside Dot "php-oci8 extension"

Then the tab downloads dot OCI8 to Http://pecl.php.net/package/oci8

And then how to download it is not much to say

Download two zip packages here, then configure PHP

Third, decompression download the first file, to the computer any directory, extract the file directory Instantclient_12 _1 suggest the back of the "_12_1" removed, after the revised version of the environment is not to move the variable

Enter this directory and double hit Open adrci.exe

Get the following command line window to prove that the client is available locally

Copy directory, mine is F:\dev\instantclient configuration to the system's PATH environment variable,

IV, unzip the downloaded DLL's compressed package, copy the Php_oci8.dll Php_oci8_11g.dll php_oci8_12c.dll I am currently the three, to PHP extension package file, usually .../php/ext/directory

In fact, can not replace, but the suggestion is to replace a good,

Then open php.ini to open the extension, the last one is added later, PHP is not, anyway on the bread in some DLL file should be written in should not be wrong, most of the time to run PHP to load a few libraries

Extension=php_pdo_oci.dll

Extension=php_oci8.dll   ; Use with Oracle 10gr2 Instant Client
extension=php_oci8_11g.dll; Use with Oracle 11gr2 Instant Client
extension=php_oci8_12c.dll; Use with Oracle 12c  Instant Client

Then restart the HTTPD service and open the Phpinfo (); Should be able to see

PDO Support enabled
PDO drivers MySQL, OCI, ODBC
 
OCI8 support enabled
OCI8 DTrace support disabled
Ve Rsion 2.0.8
Revision $Id: f04114d4d67cffea4cdc2ed3b7f0229c2caa5016 $
Oracle run-time Client Library Version 12.1.0.2.0
Oracle compile-time Instant Client Version 10.2

This means that the extension is open successfully.

Finally, the Oracle database is connected.

Here to connect an instance to the original connection http://www.orczhou.com/index.php/2010/09/php-oci8-oracle/

<?php 
//configuration information
$ora _host = "172.16.1.150";
$ora _port= "1521";
$ora _sid = "Cop";
$ora _username = "WebDev";
$ora _password = "WebDev";
$charset = "UTF8"; ### ZHS16GBK ###

//Build Easy Connect string
//(if already available in Tnsnames.ora, you can directly use connect Name)
$ora _connstr = "( Description= (address= (protocol=tcp)
(host= ". $ora _host.") (port= ". $ora _port."))
(Connect_data= (service_name= ". $ora _sid.))";
Connection database
$conn = Oci_connect ($ora _username, $ora _password, $ora _connstr);
Execute query, where $res receives a Boolean value
$stid = Oci_parse ($conn, ' select * from Dq_try_app ');
$res = Oci_execute ($stid);

The Oci_fetch_array traversal results are used in the while loop. While
($row = Oci_fetch_array ($stid, Oci_assoc+oci_return_nulls)) {
  
  foreach ($row as $item) {
    echo $item ." ***";
  }
  echo "<br>";
  
}
Var_dump ($stid);  
? >

At this point, the entire extension plus connection is complete.

The above mentioned is the entire content of this article, I hope you can enjoy.

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.