在做项目中要用到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 SQL function Execute( $sql ) { if ( $this -> conn -> Execute( $sql )) { return true ; } else { return false ; } } function Close() { $this -> conn -> Close(); } function __destruct() { // $this->conn->Close(); }} ?>