To implement the following functions, make sure that the com. allow_dcom option in php. ini is set to true.
I. Preparations
Create an ACCESS database and name it db. mdb. Then, create a new table comtest in the database, which contains the id and title fields, and insert some data at will.
II. Implementation Code
<? Php
// The database you just created
$ Db = d: \ wwwroot \ db. mdb;
// Establish a 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 the query and output data
$ Rs = $ conn-> Execute (SELECT * FROM comtest );
?>
<Table border = "1">
<Tr> <th> ID </th> <th> Title </th>
</Tr>
<? Php
While (! $ Rs-> EOF ){
Echo <tr>;
Echo <td>. $ rs-> Fields [id]-> Value. </td>;
Echo <td>. $ rs-> Fields [title]-> Value. </td>;
Echo </tr>;
$ Rs-> MoveNext ();
}
?>
</Table>
<? Php
// Release resources
$ Rs-> Close ();
$ Conn-> Close ();
$ Rs = null;
$ Conn = null;
?>