以下是代码:
/* 数据库操作类
* Author: Xiao
* Date : 2007-01-1
* E_mail:mzrxh@126.com
*/
class mydb
{ var $dbhandle;
function mydb(){
global $dbhost;
global $dbuser;
global $dbpass;
global $dbname;
$this->dbhandle=@mysql_connect($dbhost,$dbuser,$dbpass) or die("出错了!!");//连接数据库服务器
@mysql_select_db($dbname);
@mysql_query("SET NAMES 'gb2312'");//设置字符编码为gb2312
}
function fetch_row($query){//读取单行数据
$result=@mysql_query($query,$this->dbhandle) or die("查询语句错误".$query);
$result_1=@mysql_fetch_array($result);
return $result_1;
}
function fetch_array($query){//读取全部数据
$result=@mysql_query($query,$this->dbhandle);
$result_array="";$i=0;
while($temp=@mysql_fetch_array($result)){
$result_array[$i]=$temp;
$i ;
};
return $result_array;
}
function command($query){//执行SQL语句
$result=mysql_query($query,$this->dbhandle);
}
function close(){//关闭数据库连接
mysql_close($this->dbhandle);
}
}
?>