热门资源

ACCESS数据库操作类

在做项目中要用到ACCESS数据库,所以就写了一个ACCESS处理类.函数名跟ADODB类一样.

?php/**ACCESS数据库操作类*2008-3-26*LIQUAN*$dsn=DRIVER={MicrosoftAccessDriver(*.mdb)};DBQ=.PATH_ROOT.databasedata.mdb;*$conn=newAccess();*$conn-Connnect($dsn);*$conn-GetArray(select*fromtest);*/classAccess{var$conn;var$fieldsName;functionAccess(){}//connectionfunctionConnect($dsn){$this-conn=newCOM(ADODB.Connection)ordie(CannotstartADO);$this-conn-Open($dsn);}//返回一个functionGetOne($sql){$rs=$this-conn-Execute($sql);while(!$rs-EOF){$value=$rs-Fields(0)-value;$rs-MoveNext();}$rs-Close();$rs=null;if(!empty($value)){return$value;}else{return;}unset($value);}//返回大数组functionGetArray($sql){$rs=$this-conn-Execute($sql);$num_columns=$rs-Fields-Count();$rowcount=0;while(!$rs-EOF){for($i=0;$i$num_columns;$i++){$fieldName[$rowcount][$rs-Fields($i)-name]=$rs-Fields($i)-value;}$rowcount++;$rs-MoveNext();}$rs-Close();$rs=null;if(!empty($fieldName)){return$fieldName;}else{return;}unset($fieldName);}//返回小数组functionGetRow($sql){$rs=$this-conn-Execute($sql);$num_columns=$rs-Fields-Count();while(!$rs-EOF){for($i=0;$i$num_columns;$i++){$fieldName[$rs-Fields($i)-name]=$rs-Fields($i)-value;}$rs-MoveNext();}$rs-Close();$rs=null;if(!empty($fieldName)){return$fieldName;}else{return;}unset($fieldName);}//executeSQLfunctionExecute($sql){if($this-conn-Execute($sql)){returntrue;}else{returnfalse;}}functionClose(){$this-conn-Close();}function__destruct(){//$this-conn-Close();}}?

发表评论

电子邮件地址不会被公开。 必填项已用*标注

相关文章