当前位置:首页 > 数据库 > Oracle

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 );

 

      

?>

原文:http://www.cnblogs.com/semonxv/p/3831573.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐