Linux下PHP使用Oracle客户端测试

1.          下载rpm安装包,并直接安装

wget http://www.ywjt.org/pub/oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm

wget http://www.ywjt.org/pub/oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm

wget http://www.ywjt.org/pub/oracle-instantclient11.2-sqlplus-11.2.0.3.0-1.x86_64.rpm

   

    rpm -ivh oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm

    rpm -ivh oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm

rpm -ivh oracle-instantclient11.2-sqlplus-11.2.0.3.0-1.x86_64.rpm

 

2.         添加环境变量和库文件

/root/.bash_profile  加入以下内容

alias sqlplus='rlwrap sqlplus'

alias rman='rlwrap rman'

PATH=$PATH:$HOME/bin:/usr/lib/oracle/11.2/client64/bin/:/usr/local/rlwrap/bin/

export TNS_ADMIN=/etc/tnsnames.ora

ORACLE_HOME=/usr/lib/oracle/11.2/client64/

source /root/.bash_profile

 

/etc/ld.so.conf 加入以下内容

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

ldconfig

 

3.         添加tnsnames.ora 并测试

/etc/tnsnames.ora 加入以下内容

lyferp=

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.0.169)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = lyferp)

    )

  )

 

4.          使用sqlplus 测试oracle 连接是否成功

sqlplus lyferp/lyferp@lyferp

 

5.          安装OCI8 PHP扩展

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

tar zxvf oci8-1.3.5.tgz

cd oci8-1.3.5/

/usr/local/webserver/php/bin/phpize (phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块)

CFLAGS="-I/usr/include/oracle/11.2/client64/"

CXXFLAGS="-I/usr/include/oracle/11.2/client64/"

./configure --with-php-config=/usr/local/php/bin/php-config --with-oci8=instantclient,/usr/lib/oracle/11.2/client64/lib/

make && make install

 

6.          修改PHP 配置文件

/usr/local/php/etc/php.ini 添加以下内容

extension=oci8.so

 

7.          重启PHP,验证安装是否成功

新建phpinfo.php 添加以下内容

<?php

phpinfo();

?>

 

8.          执行insert测试

oracle 里新建表

create table rmantest(a varchar(100));

php 插入代码:

<?php

  $conn = oci_connect('lyferp', 'lyferp', 'lyferp');

  $query = 'INSERT into rmantest VALUES(:mydata)';

  $stid = oci_parse($conn, $query);

  for($i=1;$i<10;$i++){

   oci_bind_by_name($stid, ':mydata', $i);

   $r = oci_execute($stid);

}

   print "insert success\n";

  oci_close($conn);

?>

 

 

9.         执行select 测试:

<?php

  $conn = oci_connect('lyferp', 'lyferp', 'lyferp');

  $query = 'SELECT * FROM rmantest';

  $statement = oci_parse($conn, $query);

  oci_execute ($statement);

while ($row = oci_fetch_array ($statement, OCI_NUM)) {

    foreach ($row as $k => $v)

 //   echo "$row[$k]\n";

    echo "$v\n";

}

  oci_close($conn);

?>

 

 

你可能感兴趣的:(oracle,PHP,linux,oci8,休闲)