Make sure that the com. allow_dcom option in php. ini is set to true. 1. prepare to create an ACCESS database and name it db. mdb, and then create a new table comtest in this database, including the id and title fields to achieve the following functions, please ensure that php. com. the allow_dcom option has been 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
// 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 ');
// Perform 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 ();}?>
// Release resources
$ Rs-> Close ();
$ Conn-> Close ();
$ Rs = null;
$ Conn = null;
?>