PHP tips-use ADODB through COM. 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 named db. mdb.
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
// 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;
?>
The com. allow_dcom option in Composer php. ini has been set to true. 1. prepare to create an ACCESS database named db. mdb...