A simple example of using ADODB through COM in PHP. To implement the following functions, 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. to implement the following functions in the database, 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
// 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 ');
?>
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;
?>
Bytes. 1. prepare to create an ACCESS database and name it db. mdb. Then, create a new ACCESS database...