I am currently struggling with connecting to a MS Access database using PHP. I have checked other relevant related posts trying to get aid but to no success. I am running windows 7 and attempting to connect to (.mdb database)
I have done the following trying to resolve this:
- I have uncommented/enabled extension=php_pdo_odbc.dll in the php.ini file
- I have re-installed AccessDatabaseEngine.exe but still I am not getting any joy.
- I have tried using the 32bit Windows ODBC connector (C:\Windows\System32\odbcad32.exe) as well as the 64 bit version (C:\Windows\SysWOW64) version I am still not getting joy
- I have also tried creating a custom drivers and including it in the code bust still no joy
Please see the code below:
try {
$conn=new PDO('odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=$this->$dbName;Uid=$this->$Uid;Pwd=$this->$Upass');
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
I have created a custom driver called Microsoft Access:
try {
$conn=new PDO('odbc:DRIVER={Microsoft Access};DBQ=$this->$dbName;Uid=$this->$Uid;Pwd=$this->$Upass');
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
I get this output all the time:
SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified