Easysoft Blog

Thursday, 29 November 2019

Connecting PHP on Linux to Microsoft Access on a Windows Share

Easysoft's Microsoft Access ODBC driver enables you to work with MDB /ACCDB format databases in environments where both Linux and Windows users need to access that database.

For example, you might want to publish a Windows-based Access database on an intranet web site based on a Linux server. This the example covered in this blog.

To do this:

  1. Download the Access ODBC Driver and install and license it on your Linux web server machine.
  2. Modify the ACCESS_SAMPLE data source in odbc.ini so that it connect to the database on your Windows share. To do this:
    Driver=Easysoft ODBC-ACCESS
    # Path to the database on Linux machine
    # The SMB URL for the database file. Use this syntax for the SMB URL:
    # smb://windows_host/share/path/filename
    # The path to the libsmbclient library on the Access ODBC driver machine.
  3. Test that uou can connect in isql. For example:
    cd /usr/local/easysoft/unixODBC/bin
    ./isql.sh -v ACCESS_SAMPLE
  4. Install the PHP PDO-ODBC package and create a PHP page under your web server that connects to the Access database. For example:
      $con = odbc_connect("odbc:ACCESS_SAMPLE", "", "");
      $err = odbc_errormsg();
      if (strlen($err) <> 0) {
        echo odbc_errormsg();
      } else {
        $rs2 = odbc_exec($con, "select * from Suppliers");

Note You need to set permissions so that the user the web server is running under, e.g. www-data, has write access to the Access database file.