To implement the following functionality, please ensure that the com.allow_dcom option in php.ini is set to true.
1. Preparation
Create a new ACCESS database and name it db.mdb, then create a new table comtest in this database, containing two fields: id and title, and finally insert some data randomly.
2. Implementation code
// This is the newly created database
$db = d:wwwrootdb.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 query and output data
$rs = $conn->Execute(SELECT * FROM comtest);
?>
ID | Title |
---|---|
. $rs->Fields[id]->Value . | ;. $ rs->Fields[title]->Value . | ;