php连接oracle oracle开启扩展

<?php

/**

* 由于公司的需要,使用php+oracle开发项目,oracle因为有专门人员开发设计,我们只需远程调用

*于是乎遇到了蛋疼的问题就是开启oracle扩展的问题,虽然你在php.ini文件中打开了extension=php_oci8.dll

*单身在phpinfo中仍然看不到oracle扩展,这样oracle的操作方法就不能用,

*于是就要去oracle官方网上下载一个文件包 instantclient-basic-nt-11.2.0.3.0.zip

*解压到任意地方,然后将D:\instantclient这个地址配置到环境变量里面这样*oracle的扩展就会开启,自然方法都可以使用了,就像用mysql一样了

*当然数据库连接类还是需要的于是我就写了一个php连接oracle的类如下

*/

 

 

class oracle{

       public $user//用户

       public $pass//密码

       public $dbname;//数据库

        

       public function __construct($user=‘lms‘,$pass=‘lms‘,$dbname=‘192.168.2.77ot‘){

              $this->user=$user;

              $this->pass=$pass;

              $this->dbname=$dbname;

       }

       //连接数据库

       function conn(){

              $link = oci_connect($this->user,$this->pass,$this->dbname);

              return $link;

       }

        

        

       public function oracle_fetch_all($sql,$status=‘1‘){

              $link = $this->conn();

              if(!$status){

                     echo $sql."<br/>";

              }

              $stmt = oci_parse($link,$sql);

              $r = oci_execute($stmt);

              if (!$r ){

                     $this->oracle_error($stmt);

              }

              while(!!$row = oci_fetch_array($stmt,OCI_BOTH)){

                     $data[] = $row;

              }

              return $data;

       }

        

        

        

       public function oracle_fetch_row($sql,$status=‘1‘){

              $link = $this->conn();

              if(!$status){

                     echo $sql."<br/>";

              }

              $stid = oci_parse($link, $sql);

              $r = oci_execute($stid);

              if (!$r){

                     $this->oracle_error($stid);

              }

              $data = oci_fetch_assoc($stid);

              return $data;

       }

               

        

       public function oracle_query($sql){

              $link = $this->conn();

              $stmt = oci_parse($link,$sql);

              $r = oci_execute($stmt,OCI_DEFAULT);

              if (!$r ){

                     $this->oracle_error($stid);

              }

              return $r;

       }

               

               

       public function oracle_commit(){

              $link = $this->conn();

              $committed = oci_commit($link);

              return $committed;

       }

        

        

       public function oracle_error($stid){

              if (!empty($stid)){

                     $e = oci_error($stid);

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

              }

       }

        

        

       public function oracle_rollback(){

              $link = $this->conn();

              if (!empty($link)){

                     $r = oci_rollback($link);

              }

              return $r;

       }

 

}

 

$oracle = new oracle();

$sql = "SELECT * from T_LMS_USERS where USERID=‘2‘";

$data = $oracle->oracle_fetch_row($sql,0);

print_r ($data);

 

      

?>

php连接oracle oracle开启扩展,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。