louyaoluan 发表于 2017-4-2 14:13:03

php编写的ACCESS处理类

  php编写的ACCESS处理类
  在做项目中要用到ACCESS数据库,所以就写了一个ACCESS处理类.函数名跟ADODB类一样.
  <?php/**ACCESS数据库操作类*2008-3-26*LIQUAN*$dsn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".PATH_ROOT."databasedata.mdb";*$conn=new Access();*$conn->Connnect($dsn);*$conn->GetArray("select * from test");*/class Access{var $conn;var $fieldsName;function Access(){}//connection function Connect($dsn){$this->conn = new COM("ADODB.Connection") or die("Cannot start ADO");$this->conn->Open($dsn);}//返回一个function GetOne($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);}//返回大数组function GetArray($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);}//返回小数组function GetRow($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);}//execute SQLfunction Execute($sql){if($this->conn->Execute($sql)){return true;}else{return false;}}function Close(){$this->conn->Close();}function __destruct(){// $this->conn->Close();}}?>
页: [1]
查看完整版本: php编写的ACCESS处理类