<?php

//oracle接口类
class mydb{
	private $conn;//res to connected db
	//connect
	function connect($dbhost, $dbuser, $dbpw, $port, $dbname='',$dbcharset='')
	{
		if($dbname!='')
		{
			$hname="//".$dbhost.":".$port."/".$dbname;
		}
		else
		{
			$hname='';
		}
		
		if($hname!='')
		{
			if(!@($this->conn = oci_connect($dbuser,$dbpw,$hname)))
			{
				return false;
			}
			return true;
		}
		else
		{
			if(!@($this->conn = oci_connect($dbuser,$dbpw)))
			{
				return false;
			}
			return true;
		}
	}
	//sql执行
	function query($sql)
	{
		if(!($this->conn))
		{
			return false;
		}
		if(!($stmt=oci_parse($this->conn,$sql)))
		{
			return false;
		}
		if(!oci_execute($stmt))
		{
			return false;
		}
		if(strcasecmp(substr($sql,0,6),"select"))
		{
			return oci_commit($this->conn);
		}
		return $stmt;
	}
	//获得一行
	function fetch_row($stmt)
	{
		return @oci_fetch_row($stmt);
	}
		//fetch array
	function fetch_array($stmt)
	{
		return @oci_fetch_array($stmt);
	}
	//free result
	function free_result($stmt)
	{
		return @oci_free_statement($stmt);
	}
	
	//close
	function close()
	{
		if($this->conn)
		{
			return @oci_close($this->conn);
		}
		return true;
	}
	//total rows
	function num_rows($stmt)
	{
		return @oci_num_rows($stmt);
	}
	//total fields
	function num_fields($stmt)
	{
		@oci_num_fields($stmt);
	}
	function fetch_assoc($result)
	{
		return @oci_fetch_assoc($result);
	}
}

?>