首页 > 代码库 > php配置oci8

php配置oci8

1.下载oracle client rpm

Instant Client for Linux    http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64
oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64

$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

 

这里下这两个就可以,然后安装

 

随即会在这个目录下生成.so的文件

/usr/lib/oracle/11.2/client64/lib

$ls /usr/lib/oracle/11.2/client64/lib

$echo /usr/lib/oracle/11.2/client64/lib/ > /etc/ld.so.conf.d/oracle_client.conf

At this point, you‘re ready to register your newly-installed libraries:

$ldconfig -v

2.配置phpize

下载的版本要和php版本一致,不然装不了

http://rpm.pbone.net/index.php3/stat/4/idpl/24668595/dir/scientific_linux_6/com/php-devel-5.3.3-26.el6.x86_64.rpm.html   

php-devel-5.3.3-26 x86_64 download

 

phpize,一种构建工具,为php扩展准备构建环境。

[root@ora11g tmp]# rpm -ivh php-devel-5.3.3-26.el6.x86_64.rpm

warning: php-devel-5.3.3-26.el6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 192a7d7d: NOKEY

Preparing...                ########################################### [100%]

   1:php-devel              ########################################### [100%]

[root@ora11g tmp]# whereis phpize

phpize: /usr/bin/phpize /usr/share/man/man1/phpize.1.gz

 3.配置oci8

 https://pecl.php.net/package/oci8   oci8下载

[root@ora11g oci]# cd

oci8-1.3.3/     oci8-1.3.3.tgz  package.xml    

[root@ora11g oci]# cd oci8-1.3.3

[root@ora11g oci8-1.3.3]# ls

config.m4   CREDITS  oci8_collection.c  oci8_interface.c  oci8_statement.c  php_oci8_int.h  tests

config.w32  oci8.c   oci8.dsp           oci8_lob.c        php_oci8.h        README

[root@ora11g oci8-1.3.3]# phpize

Configuring for:

PHP Api Version:         20090626

Zend Module Api No:      20090626

Zend Extension Api No:   220090626

 

When prompted, enter either the value of $ORACLE_HOME, or instantclient,/path/to/instant/client/lib.

Note: Do not enter the variable $ORACLE_HOME because it will not be expanded. Instead, enter the actual path of the Oracle home directory.

 

If using an RPM-based installation of Oracle Instant Client, the configure line will look like this:

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

For example, --with-oci8=shared,instantclient,/usr/lib/oracle/12.1/client/lib

Note that Oracle Instant Client support first appeared in PHP 4.3.11 and 5.0.4 and originally used the option --with-oci8-instant-client to configure PHP.

 

[root@ora11g oci8-1.3.3]# ./configure -with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib

....

checking for cc option to produce PIC... -fPIC -DPIC

checking if cc PIC flag -fPIC -DPIC works... yes

checking if cc static flag -static works... no

checking if cc supports -c -o file.o... yes

checking if cc supports -c -o file.o... (cached) yes

checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes

checking whether -lc should be explicitly linked in... no

checking dynamic linker characteristics... GNU/Linux ld.so

checking how to hardcode library paths into programs... immediate

checking whether stripping libraries is possible... yes

checking if libtool supports shared libraries... yes

checking whether to build shared libraries... yes

checking whether to build static libraries... no

configure: creating ./config.status

config.status: creating config.h

config.status: executing libtool commands

 

make install

 

Libraries have been installed in:

   /tmp/oci/oci8-1.3.3/modules

 

If you ever happen to want to link against installed libraries

in a given directory, LIBDIR, you must either use libtool, and

specify the full pathname of the library, or use the `-LLIBDIR‘

flag during linking and do at least one of the following:

   - add LIBDIR to the `LD_LIBRARY_PATH‘ environment variable

     during execution

   - add LIBDIR to the `LD_RUN_PATH‘ environment variable

     during linking

   - use the `-Wl,-rpath -Wl,LIBDIR‘ linker flag

   - have your system administrator add LIBDIR to `/etc/ld.so.conf‘

 

See any operating system documentation about shared libraries for

more information, such as the ld(1) and ld.so(8) manual pages.

----------------------------------------------------------------------

Installing shared extensions:     /usr/lib64/php/modules/

 

 

$echo extension=oci8.so > /etc/php.d/oci8.ini

 

$/etc/init.d/httpd restart

 oci8的安装官方文档参考如下:

http://php.net/manual/en/oci8.installation.php

 

 4.验证下php能否连上oracle数据库:

可以看到phpinfo中的信息oci8模块已经加载了 

技术分享

 

[root@ora11g html]# more get_dbinfo.php
<?php
$db_connect = oci_connect(‘system‘, ‘xxx‘, ‘(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1
30.131)(PORT = 1521)) (CONNECT_DATA = http://www.mamicode.com/(SERVER = DEDICATED) (SERVICE_NAME = deff)))‘);

$sql_query = oci_parse($db_connect, ‘select status from v$instance‘);
oci_execute($sql_query,OCI_DEFAULT);
##echo $sql_query
while($r=oci_fetch_row($sql_query))
{
echo $r[0];
echo "<BR>";
}
?>
[root@ora11g html]# php get_dbinfo.php
OPEN<BR>[root@ora11g html]#

技术分享

 

在这里,关于php的配置全部完成,后面就是关于一些php与数据库,与shell脚本相结合做出html界面的东西。

 

=============ENDED============

 

php配置oci8