<?php
//mssql接口类
class mydb{
	private $conn;//res to connected db
	//connect
	function connect($dbhost, $dbuser, $dbpw, $port, $dbname='',$dbcharset='')
	{
		$constr=$dbhost.",".$port;
		if(!@($this->conn=mssql_connect($constr,$dbuser,$dbpw)))
		{
			return false;
		}
		if($dbname)
		{
			if(!@(mssql_select_db($dbname,$this->conn)))
			{
				return false;
			}
		}
		return true;
	}
	//query
	function query($sql)
	{
		//$sql = iconv("UTF-8", "GB18030", $sql);
		if(!($this->conn))
		{
			return false;
		}
		return @mssql_query($sql, $this->conn);
	}
	
	//fetch_row
	function fetch_row($query)
	{
		return mssql_fetch_row($query);
		/* php mssql字符集问题的解决
		$k = count($arr);
		if($k == 0)
		{
			return FALSE;
		}
		for($i = 0 ; $i < $k; ++$i)
		{
			$arr[$i] = iconv("GB18030", "UTF-8", $arr[$i]);
		}
		return $arr;
		*/
	}
	//fetch_array
	function fetch_array($query)
	{
		return mssql_fetch_array($query);
	}
	
	//free_result
	function free_result($query)
	{
		return mssql_free_result($query);
	}
	//close db
	function close()
	{
		if($this->conn)
		{
			return mssql_close($this->conn);
		}
		return true;
	}
	//total rows
	function num_rows($query)
	{
		return mssql_num_rows($query);
	}
	//total field
	function num_fields($query)
	{
		return mssql_num_fields($query);
	}
	
	function fetch_assoc($result)
	{
		return @mssql_fetch_assoc($result);
	}
}
?>