Reputation: 31
I am unable to connect to my Access database with the following code. I receive a "could not find driver" error. Can anyone offer a solution?
<?php
$mdbFileName = realpath('Project1.accdb');
try {
$dbh = odbc_connect("Driver={Microsoft Access Driver (*.mdb,*.accdb)};Dbq=$mdbFileName",'','');
if (!$dbh)
echo 'Failed3';
else
echo 'Success3';
}
catch (PDOException $e)
{
echo $e->getMessage();
}
odbc_close($dbh);
?>
Upvotes: 0
Views: 1526
Reputation: 31
My solution was to use a COM object and an OLEDB connection instead of PDO and an ODBC connection:
<?php
$dbh = new COM('ADODB.Connection') or die('Cannot start ADO');
$dbh->Open('Provider=Microsoft.ACE.OLEDB.12.0; Data Source=Project1.accdb; Persist Security Info=False;');
if (!$dbh)
echo 'Failed3';
else
echo 'Success3';
?>
Upvotes: 3