RG's
RG's

Reputation: 31

MS Access PHP Connection using PDO "could not find driver" error

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

Answers (1)

RG&#39;s
RG&#39;s

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

Related Questions