Showing posts with label oci8. Show all posts
Showing posts with label oci8. Show all posts

Tuesday, August 24, 2010

Compiled new oci8(1.4.3) in PHP(5.3.3)

How to compile new oci8 in PHP source?
oci8(PHP) is extension for Oracle Database allows you to access Oracle databases. It can be built with PHP 4.3.9 to 5.x. It can be linked with Oracle 9.2, 10.2, 11.1, or 11.2 client libraries.
When we find new version (oci8) and want to upgrade in PHP, How?
If we want to use oci8 1.4.3. we may wait PHP version 6.0.0 or older (but OCI8 1.4.2 is included in PHP 5.3.3).
So, download oci8 1.4.3 and compile in php 5.3.3:
- check PHP source path.
# pwd
/SRC/php-5.3.3
- check old configuration.
# cat config.nice

#! /bin/sh
#
# Created by configure

'./configure' \
'--with-apxs2=/usr/local/apache/bin/apxs' \
'--with-oci8=instantclient,/u01/app/instantclient_11_2' \
"$@"
- move old oci8 and use new oci8 (1.4.3)
# mv ext/oci8 ext/oci8-org
# ls ../oci8-1.4.3.tgz
../oci8-1.4.3.tgz
# tar zxvf ../oci8-1.4.3.tgz -C ext/
# mv ext/oci8-1.4.3 ext/oci8
# make clean && make
# /usr/local/apache/bin/apachectl stop
# make install
# /usr/local/apache/bin/apachectl start
- check again.
we will see new version(oci8).

Wednesday, April 01, 2009

How to install HTTP Server + PHP + InstantClient


1. Softwares.

- HTTP Server http://httpd.apache.org/
httpd-2.2.11.tar.gz

- PHP http://www.php.net/downloads.php
php-5.2.9.tar.gz (oci8 1.2.5)

- OCI8 (if need new OCI8 version) http://pecl.php.net/package/oci8/download/
oci8-1.3.5.tgz

- InstantClient http://www.oracle.com/technology/software/tech/oci/instantclient/index.html
basic-11.1.0.70-linux-x86_64.zip
sdk-11.1.0.7.0-linux-x86_64.zip

2. Install Softwares. 
- InstantClient (on /oracle/instantclient_11_1 PATH)
$ mkdir /oracle

$ cd /oracle

$ unzip SOURCE/basic-11.1.0.70-linux-x86_64.zip
Archive: SOURCE/basic-11.1.0.70-linux-x86_64.zip
inflating:
instantclient_11_1/BASIC_README
.
.
.

$ unzip SOURCE/sdk-11.1.0.7.0-linux-x86_64.zip
Archive: SOURCE/sdk-11.1.0.7.0-linux-x86_64.zip
creating:
instantclient_11_1/sdk/
.
.
.

$ ls
instantclient_11_1

$ cd instantclient_11_1

###make link soft file ###

$ ln -s libclntsh.so.11.1 libclntsh.so

$ ln -s libocci.so.11.1 libocci.so

- Install HTTP Server (Increase DEFAULT_SERVER_LIMIT > 256)
$ cd SOURCE

$ tar zxvf httpd-2.2.11.tar.gz
httpd-2.2.11/
.
.
.

$ cd httpd-2.2.11

###Increase default server limit of prefork > 256###

$ vi server/mpm/prefork/prefork.c
#define DEFAULT_SERVER_LIMIT 256 => #define DEFAULT_SERVER_LIMIT 1024
$ ./configure --prefix=/usr/local/apache --with-config-file-path=/usr/local/apache/conf --enable-ssl

$ make

$ su

# make install

- Install PHP (new oci8)
$ cd SOURCE

$ tar zxvf oci8-1.3.5.tgz
.
.
.

$ tar zxvf php-5.2.9.tar.gz
php-5.2.9/
.
.
.

$ cd php-5.2.9

###change to use new oci8###

$ mv ext/oci8 ext/oci8-old

$ mv ../oci8-1.3.5 ext/oci8

$ ./configure --prefix=/usr/local/apache --with-config-file-path=/usr/local/apache/conf \
--with-oci8=share,instantclient,/oracle/instantclient_11_1 --enable-sigchild \
--with-apxs2=/usr/local/apache/bin/apxs --disable-cli --disable-cgi

$ make

$ su

# make install

3. Configure HTTP Server and Etc.
- Add some Environments in /usr/local/apache/bin/apachectl file.
#
ARGV="$@"
#
export ORACLE_HOME=/oracle/instantclient_11_1
export NLS_LANG=AMERICAN_AMERICA.TH8TISASCII
export TNS_ADMIN=/oracle/instantclient_11_1

- Modified /usr/local/apache/conf/httpd.conf file to use .php type.

AddType application/x-httpd-php .php

- Modified Etc... on /usr/local/apache/conf/httpd.conf file.

Example:
ServerName server.domain.com
ServerAdmin admin@domain.com
User oracle
Group dba
.
.
.

- Harden Some... on HTTP Sever.
Example: (uncomment "Include conf/extra/httpd-default.conf" in /usr/local/apache/conf/httpd.conf file before)

ServerTokens Prod
ServerSignature Off
.
.
.

4. Create TNSNAME File (check "TNS_ADMIN" on HTTP Server before).
Example: /oracle/instantclient_11_1/tnsnames.ora (Because -> TNS_ADMIN=/oracle/instantclient_11_1)

DB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =
db_host)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = DB)
)
)


5. Start HTTP Server(root).
# /usr/local/apache/bin/apachectl start


### write PHP connect Oracle DB and Test at /usr/local/apache/htdocs PATH (default)###

refer: http://docs.google.com/Doc?id=dhg2wncg_12ddc9f3tn

Saturday, October 25, 2008

PHP OCI Collections



When we use oracle type, and need to write php oci. This is example use varray and fetch data by php:

create or replace type tel_obj as
varray(10) of varchar2(20);

CREATE TABLE user_info2 (
name varchar2(30),
surname varchar2(30),
tel tel_obj);


INSERT INTO user_info2
(name, surname,tel)
VALUES
('JOHN', 'SMITH', tel_obj('1111111','Bangkok'));

INSERT INTO user_info2
(name, surname,tel)
VALUES
('JOHN', 'DOWN', tel_obj('1567751234', 'Chiangmai, Thailand'));


select * from user_info2;

NAME SURNAME TEL
---------- ---------- --------------------------------------------------------
JOHN                           SMITH    TEL_OBJ('1111111', 'Bangkok')

JOHN                           DOWN       TEL_OBJ('1567751234', 'Chiangmai, Thailand')


create or replace PROCEDURE get_tel2 (v_name in VARCHAR2, v_surname in VARCHAR2, v_tel out tel_obj) IS
BEGIN
SELECT tel INTO v_tel FROM user_info2 u WHERE u.surname = v_surname and u.name = v_name;
END;
/


Example: OCI-Collection (PHP)


$name = "JOHN";
$surname = "DOWN";
$conn = oci_connect ('username','password','DB');

$tel_coll = oci_new_collection ($conn, 'TEL_OBJ'); //
Allocates new collection object

$stmt = oci_parse($conn, "begin GET_TEL2(:name, :surname, :tel); end;");

oci_bind_by_name($stmt, ":name", $name, 30);

oci_bind_by_name($stmt, ":surname", $surname, 30);
oci_bind_by_name($stmt, ":tel", $tel_coll, -1, OCI_B_NTY); //bind with collection

oci_execute($stmt,OCI_DEFAULT);

print "TEL: " . $tel_coll->getElem(0) . ", Location: " . $tel_coll->getElem(1);

oci_close($conn);

?>

Show:
TEL: 1567751234, Location: Chiangmai, Thailand
.
.
.

Tuesday, July 22, 2008

PHP + OCI8 + instantClient

We need to install PHP support OCI8 1.3.X (this is new oci8 support 11g, that can create connection pool) with instantClient (download basic-11.1.0.6.0-linux-x86_64.zip + sdk-11.1.0.6.0-linux-x86_64.zip).

Assume:

1. Used Linux x86_64
2. Installed Apache2 HTTP at /usr/local/apache/ PATH.

After that We install PHP =>

Begin -> download instantClient + SDK and install:

$ mkdir /oracle
$ cd /oracle
$ unzip /tmp/basic-11.1.0.6.0-linux-x86_64.zip
Archive: /tmp/basic-11.1.0.6.0-linux-x86_64.zip
inflating: instantclient_11_1/BASIC_README
inflating: instantclient_11_1/adrci
inflating: instantclient_11_1/genezi
inflating: instantclient_11_1/libclntsh.so.11.1
inflating: instantclient_11_1/libnnz11.so
inflating: instantclient_11_1/libocci.so.11.1
inflating: instantclient_11_1/libociei.so
inflating: instantclient_11_1/libocijdbc11.so
inflating: instantclient_11_1/ojdbc5.jar
inflating: instantclient_11_1/ojdbc6.jar

$ unzip /tmp/sdk-11.1.0.6.0-linux-x86_64.zip
Archive: /tmp/sdk-11.1.0.6.0-linux-x86_64.zip
creating: instantclient_11_1/sdk/
creating: instantclient_11_1/sdk/include/
inflating: instantclient_11_1/sdk/include/occi.h
inflating: instantclient_11_1/sdk/include/occiCommon.h
inflating: instantclient_11_1/sdk/include/occiControl.h
inflating: instantclient_11_1/sdk/include/occiData.h
inflating: instantclient_11_1/sdk/include/occiObjects.h
inflating: instantclient_11_1/sdk/include/occiAQ.h
inflating: instantclient_11_1/sdk/include/oci.h
inflating: instantclient_11_1/sdk/include/oci1.h
inflating: instantclient_11_1/sdk/include/oci8dp.h
inflating: instantclient_11_1/sdk/include/ociap.h
inflating: instantclient_11_1/sdk/include/ociapr.h
inflating: instantclient_11_1/sdk/include/ocidef.h
inflating: instantclient_11_1/sdk/include/ocidem.h
inflating: instantclient_11_1/sdk/include/ocidfn.h
inflating: instantclient_11_1/sdk/include/ociextp.h
inflating: instantclient_11_1/sdk/include/ocikpr.h
inflating: instantclient_11_1/sdk/include/ocixmldb.h
inflating: instantclient_11_1/sdk/include/odci.h
inflating: instantclient_11_1/sdk/include/oratypes.h
inflating: instantclient_11_1/sdk/include/ori.h
inflating: instantclient_11_1/sdk/include/orid.h
inflating: instantclient_11_1/sdk/include/orl.h
inflating: instantclient_11_1/sdk/include/oro.h
inflating: instantclient_11_1/sdk/include/ort.h
inflating: instantclient_11_1/sdk/include/xa.h
inflating: instantclient_11_1/sdk/include/nzt.h
inflating: instantclient_11_1/sdk/include/nzerror.h
creating: instantclient_11_1/sdk/demo/
inflating: instantclient_11_1/sdk/demo/demo.mk
inflating: instantclient_11_1/sdk/demo/cdemo81.c
inflating: instantclient_11_1/sdk/demo/occidemo.sql
inflating: instantclient_11_1/sdk/demo/occidemod.sql
inflating: instantclient_11_1/sdk/demo/occidml.cpp
inflating: instantclient_11_1/sdk/demo/occiobj.cpp
inflating: instantclient_11_1/sdk/demo/occiobj.typ
inflating: instantclient_11_1/sdk/SDK_README
extracting: instantclient_11_1/sdk/ottclasses.zip
inflating: instantclient_11_1/sdk/ott

$ cd instantclient_11_1/

create link libraries:
$ ln -s libclntsh.so.11.1 libclntsh.so
$ ln -s libocci.so.11.1 libocci.so


Download PHP + new OCI8 (http://oss.oracle.com) and then patch OCI8 + install PHP with Apache2:

$ tar zxvf php-5.2.6.tar.gz
$ cd php-5.2.6/ext/
$ mv oci8 oci8-old
$ tar zxvf /tmp/oci8-1.3.x.tgz
$ ln -s oci8-1.3.x oci8
$ cd ..

$ export ORACLE_HOME=/oracle/instantclient_11_1/
$ pwd
/tmp/php-5.2.6

$ ./configure --prefix=/usr/local/apache --with-config-file-path=/usr/local/apache/conf \
--enable-sigchild --with-apxs2=/usr/local/apache/bin/apxs \
--with-oci8=share,instantclient,/oracle/instantclient_11_1/

$ make

$ su # use "root" user to install

$ make install

copy file (php.ini-dist or php.ini-recommended) for php.ini
$ cp php.ini-dist( or php.ini-recommended) /usr/local/apache/conf/php.ini

Add Type in httpd.conf file and start Apache2
.......
AddType application/x-httpd-php .php
.......

>>> create tnsnames.ora file "/oracle/instantclient_11_1/tnsnames.ora"

DB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = db_host)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = DB)
)
)

>>>

Anyway, before start apache, we should set ORACLE ENV:

- ORACLE_HOME
- ORACLE_SID
- LD_LIBRARY_PATH
- NLS_LANG
- TNS_ADMIN

The NLS_LANG and TNS_ADMIN variables are most likely to be required for Zend Core for Oracle. Zend Core for Oracle modifies apachectl and adds LD_LIBRARY_PATH. (This may not be required in a future version of Zend Core for Oracle if Oracle links the Instant Client differently).

This allows the Zend Core for Oracle GUI Console to be reused to start Apache. If you are using a tnsnames.ora fi le and specify network aliases for the connection string with Zend Core for Oracle, you may need to do something similar with TNS_ADMIN so the Zend Core for Oracle Console can restart Apache correctly. If you start Apache manually, set the environment in a calling script.

>>> This case we created "tnsnames.ora" file at /oracle/instantclient_11_1/ PATH, So

$ export TNS_ADMIN=/oracle/instantclient_11_1/

$ /usr/local/apache/bin/apachectl start

create Code to test PHP + Oracle =>

$c = oci_connect('username', 'password', 'db');

We can find out PHP + Oracle at http://www.oracle.com/technology/tech/php/index.html