title: Accessing MDB file with PHP on CentOS machine
body: <p>I am trying to access a MDB file using PHP on a CentOS machine, preferably using PDO. I have installed the ODBC and pdo_odbc modules in PHP and restarted the the web server (Apache). I also installed mdbtools and unixODBC. </p>
  
  <pre><code>print_r(PDO::getAvailableDrivers());
  </code></pre>
  
  <p>Shows:</p>
  
  <pre><code>Array
  (
      [0] =&gt; mysql
      [1] =&gt; odbc
      [2] =&gt; pgsql
      [3] =&gt; sqlite
  )
  </code></pre>
  
  <p>I try to access the DBA file (which is saved locally) with this code:</p>
  
  <pre><code>try
  {
      $driver = "/usr/lib64/libmdbodbc.so.0";
      $dbName = "/PATH/FILE.MDB";
      if (!file_exists($dbName)) {
          die("Could not find database file.");
      }
      $db = new PDO("odbc:DRIVER=$driver; DBQ=$dbName; Uid=; Pwd=;");
  
      $sql  = "SHOW TABLES";
  
      $result = $db-&gt;query($sql);
      $row = $result-&gt;fetch();
  
      var_dump($row);
  
  }
  catch(Exception $e)
  {
      echo "\n\nEXCEPTION: $e\n\n";
  }
  </code></pre>
  
  <p>And this outputs:</p>
  
  <pre><code>EXCEPTION: exception 'PDOException' with message 'SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified' in /PATH/odbctest.php:14
  Stack trace:
  #0 /PATH/odbctest.php(14): PDO-&gt;__construct('odbc:DRIVER=/us...') 
  #1 {main}
  </code></pre>
  
  <p>What do I need to change? What should I use as a driver name? I have been looking all over the place and all I find is a lot of really old stuff from the 2004 era, but a lot of the links have disappeared over the years. This is the most relevant StackOverflow question, but does not include any code: <a href="https://stackoverflow.com/questions/5838499/pdo-microsoft-access">PDO Microsoft Access</a>. I really only need to read from the file.</p>
  
  <p>EDIT:</p>
  
  <p>With some tinkering it seems that I now at least have PDO happy with the driver by correcting the odbcinst.ini file which now contains the following:</p>
  
  <pre><code>[MDBTools]
  Description = MDBTools Driver
  Driver64    = /usr/lib64/libmdbodbc.so.0
  Setup       = /usr/lib64/libmdbodbc.so.0
  FileUsage   = 1
  UsageCount  = 1
  </code></pre>
  
  <p>Unfortunately, I am still getting an error:</p>
  
  <pre><code>exception 'PDOException' with message 'SQLSTATE[08001] SQLDriverConnect: 1 [unixODBC]Could not find DSN in connect string' in /PATH/odbctest.php:15
  Stack trace:
  #0 /PATH/odbctest.php(15): PDO-&gt;__construct('odbc:Driver=MDB...')
  #1 {main}
  </code></pre>
  
  <p>I am making the PDO call as follows:</p>
  
  <pre><code>$driver = "MDBTools";
  $dbName = "/PATH/DATABASE.MDB";
  $db = new PDO("odbc:Driver=$driver; DBQ=$dbName; Uid=; Pwd=;");
  </code></pre>
  
  <p>I tried adding the data source to the odbc.ini file even though I can't do this in the production version and am still getting the same error. I did find this which is interesting: <a href="https://stackoverflow.com/questions/10090172/dsn-less-connection-with-php-odbc-using-mdbtools-driver">DSN-less connection with PHP ODBC using MDBTools Driver</a>. Any suggestions?</p>