0

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:

  1. I have uncommented/enabled extension=php_pdo_odbc.dll in the php.ini file
  2. I have re-installed AccessDatabaseEngine.exe but still I am not getting any joy.
  3. 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
  4. 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
  • 1
    And what is the error message you receive on failed attempts? Also, be sure `$dbname` points to a full path. MS Access like SQLite is a file-level database and not server-level. – Parfait Mar 13 '16 at 15:18
  • I have tried using realpath() to try and target the overall path. – Andi Masikhwa Mar 14 '16 at 18:55
  • And again, what is the error/exception message php outputs. *No joy* is not helpful. – Parfait Mar 14 '16 at 20:10
  • Hi Sorry, I modified my post. I get this error: SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified – Andi Masikhwa Mar 14 '16 at 20:53
  • 1
    What version of PHP are you running ([32-bit or 64-bit](http://stackoverflow.com/questions/5423848/checking-if-your-code-is-running-on-64-bit-php))? If 32-bit, try this driver: `DRIVER={Microsoft Access Driver (*.mdb)}`. – Parfait Mar 14 '16 at 22:58
  • I have tried that driver you supplied but I still get the same error. The Current PHP version: 5.4.3 and it is running on 32 bit. – Andi Masikhwa Mar 15 '16 at 07:34
  • See this link: https://stackoverflow.com/questions/24712708/php-debugging-pdo-connection-to-access-database-accdb?rq=1 – Benjamin Swedlove Jun 13 '17 at 23:58

0 Answers0