phplinuxphp-7.2pdo-odbc

How to enable PDO_ODBC on Linux?


I want to run Microsoft Access Database using PDO_ODBC (on Centos 7 x64 bit). But unfortunately i get this error on the page :

could not find driver

First of all i am looking the problem through my connection.php, but seems like there is no problem in my code (tested on Windows 7 x64 bit).

And then i think the driver has not enabled yet, i look into phpinfo() page and yes the driver has not enabled yet.

And then i go into php.ini to enable the driver. I uncomment the following line in php.ini:

extension=pdo_odbc

And then i restart the apache using this command:

# /etc/init.d/apache2 restart

After that i look into phpinfo() page, unfortunately the setting that i have set has not enabled yet, this is the screenshot for the phpinfo(): phpinfo() page.

Would you tell me how to enable PDO_ODBC on Linux (CentOS 7)?

UPDATE TO SHOW MY CONNECTION

connection.php:

<?php 

    $dsn = "{Microsoft Access Driver (*.mdb, *.accdb)}";
    $db = "/home/www/html/cetak_absensi/uploaded/db_access/my_access_db.mdb";
    $user = "";
    $pass = "";

    if (!file_exists($db)) {
        die("File is not exists ! " . $db);
    }else{
        try {
            $koneksi = new PDO("odbc:DRIVER=".$dsn.";charset=UTF-8; Dbq=".$db."; Uid=".$user."; Pwd=".$pass.";");
            $koneksi->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        } catch (PDOException $e) {
            echo "There is an error : <i>" . $e->getMessage() . "</i>";
            die();
        }
    }

Solution

  • Driver and extension are not the same thing.

    You can find the driver on microsoft.com website, like this or similiar for your specific version requirement:

    https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15

    You could also try to install a GNU package like "FreeTDS".

    The other problem is, you are editing the wrong php.ini file.

    When running php -i | grep.... you are executing the cli SAPI of PHP in /etc/php/7.2/cli/php.ini, but what you actually want is the apache SAPI php.ini, most probably located at /etc/php/7.2/apache/php.ini. Go to your php_ini() URL, the correct path is shown in the first or second table presented.