To implement the following features, make sure that the com.allow_dcom option in PHP.ini is set to true.
First, the preparatory work
Create a new Access database and name it Db.mdb, and then create a new table Comtest in the database, containing the ID and title two fields, and finally inserting some data.
Second, the implementation of the Code
Is the database that was just built.
$db = ' D:\\wwwroot\\db.mdb ';
Establish the connection and open
$conn = new COM (' ADODB. Connection ') or die (' Can not start Active X Data Objects ');
$conn->open ("Provider=Microsoft.Jet.OLEDB.4.0; Data source= $db ");
$conn->open ("Driver={microsoft Access DRIVER (*.mdb)}; dbq= $db ");
Execute Query and output data
$rs = $conn->execute (' SELECT * from Comtest ');
?>
ID |
Title |
while (! $rs->eof) {echo '
'; Echo '
'. $rs->fields[' id ']->value. ' | '; Echo '
'. $rs->fields[' title ']->value. ' | '; Echo '
'; $rs->movenext (); }?>
Freeing resources
$rs->close ();
$conn->close ();
$rs = null;
$conn = null;
?>
The above describes the Adodb.recordset PHP through the use of COM ADODB Simple example, including the adodb.recordset aspect of the content, I hope that the PHP tutorial interested in a friend helpful.