试用php中oci8扩展

yipeiwu_com6年前PHP代码库

给大家分享个php操作Oracle的操作类

Oracle_db.class.php

<?php
class Oracle_db{
  public $link;
  public function __construct(){
    $this->link=$this->connect();
    if(!$this->link){
      echo "连接失败";
      exit;
    }
  }
  public function connect(){
    return oci_connect('demo','demo','localhost/xe','AL32UTF8');
  }
  public function execute($sql){
    $result=false;
    $stid=oci_parse($this->link,$sql);
    if($stid){
      $result=oci_execute($stid);
    }
    return array($stid,$result);
  }
  public function fetch_assoc($stid){
    return oci_fetch_assoc($stid);
  }
  
  public function fetch_one($stid){
    $arr=$this->fetch_assoc($stid);
    $this->free($stid);
    return $arr;
  }
  public function fetch_all($stid){
    $arr=array();
    while($row=$this->fetch_assoc($stid)){
      $arr[]=$row;
    }
    $this->free($stid);
    return $arr;
  }
  public function num_rows($stmt){
    return oci_num_rows($stmt);
  }
  public function error(){
    return oci_error($this->link);
  }
  public function free($stid){
    return oci_free_statement($stid); 
  }
  public function server_version(){
    return oci_server_version($this->link);
  }
  public function client_version(){
    return oci_client_version();
  }
  public function __destruct(){
    return oci_close($this->link);
  }
  //
}

以上所述就是本文的全部内容了,希望大家能够喜欢

相关文章

php校验公钥是否可用的实例方法

ssh如何利用RSA公钥进行远程登录验证 1、本地机器生成密钥 $ssh-keygen -t rsa 生成基于ssh协议第二版密钥,如果还是用rsa1,该升级了。 2、复制生...

PHP基于Closure类创建匿名函数的方法详解

本文实例讲述了PHP基于Closure类创建匿名函数的方法。分享给大家供大家参考,具体如下: Closure 类 用于代表匿名函数的类。 匿名函数(在 PHP 5.3 中被引入)会产生这...

php生成随机数的三种方法

如何用php生成1-10之间的不重复随机数? 例1,使用shuffle函数生成随机数。 <?php $arr=range(1,10); shuffle($arr); f...

PHP中使用file_get_contents抓取网页中文乱码问题解决方法

本文实例讲述了PHP中使用file_get_contents抓取网页中文乱码问题解决方法。分享给大家供大家参考。具体方法如下: file_get_contents函数本来就是一个非常优秀...

php将字符串转换成16进制的方法

本文实例讲述了php将字符串转换成16进制的方法。分享给大家供大家参考。具体分析如下: php中可以通过bin2hex函数将字符串转换成16进制的形式输出,bin2hex()函数返回结果...