|
|
 |
|
Title: Microsoft Access Database Connectivity
Submitter: Daniel Hendricks
(other recipes)
Last Updated: 2002/04/28
Version no: 1.0
Category:
Databases
|
|
1 vote(s)
|
|
|
|
Description:
This is an example of how you can pull data from a Microsoft Access database through ADO.
Source: Text Source
<?
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\\inetpub\\wwwroot\\php\\mydb.mdb");
$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>";
while (!$rs->EOF) {
$fv = $rs->Fields("myfield");
echo "Value: ".$fv->value."<br>\n";
$rs->MoveNext();
}
$rs->Close();
?>
Discussion:
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.
|
|
Add comment
|
|
Number of comments: 5
OLEDB in place of ODBC, Jason Brown, 2002/09/01
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/
Add comment
Agree, Morten Moe, 2004/07/23
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;");
Add comment
Richie Cahipe, 2006/05/17
Add comment
returned value, fred koehler, 2005/11/10
hi!
im kind of new with this code, so i have two questions:
1. what value is returned when i changed something in the db? i need something like that:
$change = $db->Execute("UPDATE termintab SET titel='$ftitel', link='$flink WHERE newsid='$fid'");
if ($change = TRUE){...}
2. how can i check if there is anything in one line of the db, like: $check = odbc_result($db, title);
with the $result-> thing
and what is the returned value here, like
if ($result = TRUE){...}
thanks for an answer!
burns
Add comment
Richie Cahipe, 2006/05/17
Add comment
|
|
|
|
|
 |
|