Microsoft access with PHP and PDO

10,954

Write the connection object like the following and save characters case.

$dbName = "E:\\path\\to\\db.mdb";
 $db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)};charset=UTF-8; DBQ=$dbName; Uid=; Pwd=;");
Share:
10,954
Veronica
Author by

Veronica

Updated on August 23, 2022

Comments

  • Veronica
    Veronica over 1 year

    I am trying to connect to my access database but cannot. I have on my Microsoft server 2008 with IIS 7. I keep getting this error message. SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified. Not Sure what I am doing wrong. Any ideas would help.

    <?php
    try {
    
     $conn = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\\staffing.mdb;Uid=Admin");
    
    }
    catch (PDOException $e) {
      echo $e->getMessage();
    }
    ?>
    
  • Veronica
    Veronica over 9 years
    Thank you that worked Now I just have to figure how to query the access DB with PHP and PDO
  • Veronica
    Veronica over 9 years
    I was able to query the db just can't get my javascript code to work stackoverflow.com/questions/27068866/…
  • JustCarty
    JustCarty over 5 years
    FWIW I had this problem and was tearing my hair out for ages. I was using the driver Microsoft Access Driver (*.mdb, *.accdb) instead of the one used in the answer. Thank you so much!
  • JustCarty
    JustCarty over 4 years
    A year later, and I can say that the real reason I couldn't get this to work is that I hadn't got the 64-bit version of the Access driver on my server.