计算机一级辅导:MYSQL的操作类(已封装)
发布时间:2010/3/17 17:02:53 来源:城市学习网 编辑:moon
【导读】本文封装了一个按照ADO的习惯书写的MYSQL的操作类,供参考学习。class MySQLDB
function MySqlDB //构造函数
$this-dbid=mysql_select_db;
if
}
function IsEmpty
function Destroy //数据清除处理
function PrintErr
else
}
function Execute //直接执行SQL语句
$this-sSQL=$SQL;
if)
return true;
}
function Query //在数据库里执行查询
$this-nOffset=0;
$this-nRows=mysql_num_rows;
$this-nCols=mysql_num_fields;
if
$this-EOF=false;
else
$this-EOF=true;
unset;
$this-aFName=array;
for
$this-aFName[$i]=strtolower);
}
function MoveNext
$this-nOffset++;
if
$this-EOF=true;
}
function MoveTo
if
$this-nOffset=$Offset;
}
//得到指定行的指定列的值,返回字符串
//如果不指定Offset将取得下一行的值
//如果不指定nFields将取得该行的值,并已数组形式返回
function GetValue
if
}
if)
$aResult=mysql_fetch_row;
if$nFields-1)
return $aResult[$nFields];
}
if)
if
return $aResult[$i];
}
return $aResult;
}
function AddNew //标志开始添加数据
if)
unset;
$this-aNew=array;
$this-NewEdit=1;
$strSQL="selectfrom ".$this-sTName;
$this-sSQL=$strSQL;
if)
$this-nCols=mysql_num_fields;
unset;
$this-aFName=array;
for
$this-aFName[$i]=strtolower);
}
function Edit //对指定数据库表进行编辑
unset;
$this-aNew=array;
$this-NewEdit=2;
$strSQL="selectfrom ".$this-sTName;
$this-sSQL=$strSQL;
if)
$this-nCols=mysql_num_fields;
unset;
$this-aFName=array;
for
$this-aFName[$i]=strtolower);
}
function SetValue //指定数据,跟在AddNew后执行;
if)
$this-aNew[$Index]=$Value;
$tmpIn=$Index;
}
elseif)
if
$this-aNew[$i]=$Value;
$tmpIn=$i;
}
if)
$this-sName.=",";
$this-sName.=$this-aFName[$tmpIn];
//根据当前字段的类型生成相应的新值
if
$this-sValue.=",";
else
$this-sValue="";
$ftype=@mysql_field_type;
//echo;
switch
if
$this-sName.="=".$this-sEdit;
}
function Update //存储新值到数据库
if)
switch
$this-sSQL=$strSQL;
if)
//echo;
//作清理工作
$this-NewEdit=0;
unset;
mysql_query;
}
}