This is an example of how you can pull data from a Microsoft Access database through ADO.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
// Microsoft Access connection string.
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\\inetpub\\wwwroot\\php\\mydb.mdb");
// SQL statement to build recordset.
$rs = $conn->Execute("SELECT myfield FROM mytable");
echo "<p>Below is a list of values in the MYDB.MDB database, MYABLE table, MYFIELD field.</p>";
// Display all the values in the records set
while (!$rs->EOF) {
$fv = $rs->Fields("myfield");
echo "Value: ".$fv->value."<br>\n";
$rs->MoveNext();
}
$rs->Close();
?>
|
This code is useful for those who want to use a Microsoft Access database with a PHP script. This code works on Microsoft Windows only, so you might want to check with your service provider before attempting to use this.
Tags: database
OLEDB in place of ODBC. to improve performance and reliability, it's recommended that OLEDB is used in place of ODBC
replace this line
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\inetpub\wwwroot\php\mydb.mdb");
with
$conn->Open("Provider=Microsoft,.Jet.OLEDB.4.0; Data Source=C:\inetpub\wwwroot\php\mydb.mdb");
Atrax http://www.atrax.ws/
Agree. OleDB sure is faster, at least in my experience. But i got problems with the connectionstring because I need to connect to a password protected ACCESS database. Anyway I thought I should post the solution in case others run into the same problems :) Here's the connection string I use:
$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Jet OLEDB:Database Password=thepassword;Data Source=E:\website\db.mdb;");
returned value. hi!
im kind of new with this code, so i have two questions:
$change = $db->Execute("UPDATE termintab SET titel='$ftitel', link='$flink WHERE newsid='$fid'");
if ($change = TRUE){...}
with the $result-> thing
and what is the returned value here, like
if ($result = TRUE){...}
thanks for an answer!
burns
Hi, I have used the code but I am getting the following error.
Fatal error: Class 'COM' not found in /demo/index.php on line 22
How can I fix it?
Hi, I am very new to php, I want to use dsn less oledb driver for Ms Access 2003, but can not find documentation for required objects and methods; e.g $rs->RecordCount(), getarray() etc.