php-oracle

Oci客户端安装

oracle-instantclient18.3-basic-18.3.0.0.0-1.x86_64.rpm

oracle-instantclient18.3-devel-18.3.0.0.0-1.x86_64.rpm

oracle-instantclient18.3-sqlplus-18.3.0.0.0-1.x86_64.rpm

下载地址:

https://pan.baidu.com/share/init?surl=yzr3Kc7uUHiHwGv4DvylWQ

网盘密码:r6e6

安装rpm包

yum installoracle-instantclient18.3-basic-18.3.0.0.0-1.x86_64.rpm

yum installoracle-instantclient18.3-devel-18.3.0.0.0-1.x86_64.rpm

yum installoracle-instantclient18.3-sqlplus-18.3.0.0.0-1.x86_64.rpm

连接数据库

/usr/lib/oracle/18.3/client64/bin/sqlplususr/pwd@//host:port/sid

安装oci8

wgethttp://pecl.php.net/get/oci8-2.0.10.tgz

tar -vxf oci8-2.0.10.tgz

cd oci8-2.0.10

phpize

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

make

make test

make install

安装pdo_oci扩展

方法一:源码包安装

进入php 源码的ext/pdo_oci 文件夹

/usr/local/bin/phpize

./configure --with-pdo-oci=instantclient,/opt/oracle/instantclient,12.2--with-php-config=/usr/local/bin/php-config

sudo make

sudo make install

方法二:使用 PDO_OCI 扩展包安装

Thinkphp 3.2.3 full对oracle的处理不够好


所以这里记录下:

M方法在查询oracle视图的时候会自动分割表名称,导致数据库表不存在,所以无法使用。

New Model() 方法只能构建本地的数据库链接,所以此方法不可用。

最后只能使用原生的驱动处理:

PDO驱动


/*

*oracle驱动测试

*/

    public function test(){

       echo date("Y-m-d H:i:s",time());

$dbms = 'oci';

$host = '192.168.253.8:1521';

$dbname='orcl';

$user = 'hongxiutao';

$pass = 'hongxiutao123';

$dsn = "$dbms:dbname=//$host/$dbname;charset=UTF8";

 try{

       $dbh = new \PDO($dsn,$user,$pass);

       echo "connect success";

       foreach($dbh->query('select * from YSZZ.VW_OFFICE_HXT limit 10') as$row){

                var_dump($row);

                }

       $dbh = null;

       }catch(PDOException $e){

       die("Error!:".$e->getMessage()."
");

}

       $db = M('',null,'DB_CONFIG1');

       $list = $db->query("select * from YSZZ.VW_OFFICE_HXT");

       var_dump($list);

}

Oci8驱动

$con =oci_connect('hongxiutao','hongxiutao123','192.168.253.8:1521/orcl','utf8');

if($con){

 echo "Oracle connected succees!";

}else{

 echo "Oracle connected fail!\n";

  $e= oci_error();

 trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);

}

$stid = oci_parse($con, 'select * fromYSZZ.VW_USER_HXT');

oci_execute($stid);

while ($row = oci_fetch_array($stid,OCI_ASSOC+OCI_RETURN_NULLS)) {

   var_dump($row);

   foreach ($row as $item) {

//      printf($item !== null ? htmlentities($item, ENT_QUOTES) :"dddd");

    }

   }

推荐阅读更多精彩内容