3

I just installed unixODBC in order to access my .mdb data source on PHP.5.3 CentOS 6.10 using this commands:

# yum install unixODBC  

In Windows i could simply uncomment extension=php_pdo_odbc.dll on php.ini and restart Httpd / Apache in order to access my .mdb, and then made connection thorugh PDO like this :

<?php

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

    $connection = new PDO("odbc:DRIVER=".$dsn.";charset=UTF-8; Dbq=".$db."; Uid=".$user."; Pwd=".$pass.";");
    ...
    ...
?>

After installed unixODBC and PDO-ODBC already running on my php, i run my code above, unfortunately i face this error :

[unixODBC][Driver Manager]Data source name not found, and no default driver specified php linux

After searched on another post here, i think my DSN is not correct.

What is the correct DSN for this in Linux ?

Is that really possible to access my .mdb data source through PHP-PDO in Linux especially CentOS 6.10?

UPDATE

After searched i have found an article explained about this. And i installed libmdodbc1 from this resource libmdbodbc and add following line in /etc/odbcinst.ini :

# Source Came From:
# 1. https://centos.pkgs.org/6/forensics-x86_64/libmdbodbc1-0.7-43.13.el6.x86_64.rpm.html
# 2. https://gist.github.com/amirkdv/9672857
# etc.
[MDBTools]
Description = MDBTools Driver
Driver64      = /usr/lib64/libmdbodbc.so.1.0.0
Setup64       = /usr/lib64/libmdbodbc.so.1.0.0
FileUsage   = 1
UsageCount  = 1

And then i change the connection like this:

connection.php

<?php
    /*
    ini_set('upload_max_filesize', '100M');
    ini_set('post_max_size', '100M');
    echo ini_get('upload_max_filesize'), ", " , ini_get('post_max_size');
    echo php_uname();
    */
    set_time_limit(600);

    $query = 'SELECT * FROM LEAVECLASS1';
    $mdb_file = '/var/www/html/cetak_absensi/uploaded/db_access/db_absensi_backup.mdb';
    $uname = explode(" ",php_uname());
    print_r($uname);
    $os = $uname[0];
    echo "<br>";
    echo $os;
    switch ($os){
      case 'Windows':
        $driver = '{Microsoft Access Driver (*.mdb)}';
        break;
      case 'Linux':
        $driver = 'MDBTools';
        break;
      default:
        exit("Don't know about this OS");
    }
    $dataSourceName = "odbc:Driver=$driver;DBQ=$mdb_file;";
    echo "<br>";

    try {
        $connection = new \PDO($dataSourceName);
        $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        $result = $connection->prepare($query);
        $result->execute();
        $data = $result->fetchAll(\PDO::FETCH_ASSOC);
    } catch (PDOException $e) {
        echo "<br><br>";
        echo "There is an error " . $e->getMessage();
        echo "<br><br>";
    }

    // I think this following code cause this error:
    //$result = $connection->query($query)->fetchAll(\PDO::FETCH_ASSOC);

    echo "<br>";
    print_r($data);
    echo "<br>";
    var_dump($connection);

After run this code the browser said :

The connection was reset

I have increased my memory_limit and max_execution_time in php.ini but still throw the same message.

Can you tell me why the browser throw this message ?

Maybe i have set wrong configuration or my .mdb data is too large.

UPDATE 2

I uninstalled my libmdodbc1 (my previous libmdodbc on first update above). And then installed libmdodbc1 using $ sudo yum install libmdodbc1 and my configuration in /etc/odbcinst.ini is still same like previous (same as on first update above) and then restarted the service. My reference is this article How to handle MS Access MDB files in Linux with PHP5 PDO and ODBC.

Furthermore i changed $mdb_file variable to $mdb_file = '/var/www/html/cetak_absensi/uploaded/db_access/db_new.mdb' that only has a table with 3 records in it. And also i added var_dump($data); to see the fetched data.

db_new.mdb looks like this:

ID  Nama Depan     Nama Belakang      Pekerjaan
1   First Name 1    Last Name 1       Programmer
2   First Name 2    Last Name 2       Guru
3   First Name 3                      Dokter

After i ran connection.php, var_dump($connection); and var_dump($data) respectively result :

// var_dump($connection);
object(PDO)#1 (0) { }

// var_dump($data);
array(2) { [0]=> array(4) { ["ID"]=> string(1) "2" ["Nama Depan"]=> NULL ["Nama Belakang"]=> NULL ["Pekerjaan"]=> NULL } [1]=> array(4) { ["ID"]=> string(1) "3" ["Nama Depan"]=> NULL ["Nama Belakang"]=> NULL ["Pekerjaan"]=> NULL } }

(END OF FIRST TRIAL).

Why $data only has fieldnames with NULLs value ?

Thought the connection already made it, i tested with my previous .mdb file (db_absensi_backup.mdb) and the page still showing the same issue.

The connection was reset

And the error_log said:

[Tue Jun 02 14:47:12 2020] [notice] child pid 5366 exit signal Segmentation fault (11)

(END OF SECOND TRIAL).

The first trial on this second update is almost made it, while the second trial with my real .mdb file seems like the package is out of date.

Can you tell me why these happened ?

And are these because i made wrong configuration before ?

  • I have searched for about 3 weeks and have not solved this yet. Any help would be appreciated ! – Dont Bullying Me May 20 '20 at 03:58
  • It would be interesting to know where exactly the connection was reset. By the server in http context? By the database file? What is the relevant output from `phpinfo()`? – Daniel W. May 25 '20 at 13:29
  • @DanielW. : i don't know exactly what you want to know in the `phpinfo()` page. But in `phpinfo()` surely my `odbc`, `pdo` and `pdo_odbc` are already enabled. And my _.mdb_ file is about 172MB. – Dont Bullying Me May 25 '20 at 14:21
  • @DanielW. By the way `var_dump($connection)` results `object(PDO)#1 (0) { }` in code above, while after i added `$result = $connection->prepare($query); $result->execute(); $data = $result->fetchAll(\PDO::FETCH_ASSOC);` line then the `The connection was reset`occur in browser. Is that because my file is too large ? – Dont Bullying Me May 25 '20 at 14:26
  • You could easily test that by using a blank MDB but I don't think it is too large. You should investigate why the connection is getting reset. What error is written to your PHP logfile? – Daniel W. May 25 '20 at 14:59
  • @DanielW.: I have tested with very small .mdb data source which only contain a table and you are right still not working. And my error_log give a notice : `[notice] child pid 5849 exit signal Segmentation fault (11)`, this is the last notice after i ran my code. – Dont Bullying Me May 25 '20 at 15:55
  • Ok, segmentation fault is the worst of all errors, because it is very hard to debug and originating from C code, not from PHP. Make sure there is no compatibility issue between your installed extensions and drivers. – Daniel W. May 25 '20 at 17:19
  • 1
    `yum install unixODBC` might give you a version of unixODBC that is rather old. use `odbcinst -j` to check the version and consider upgrading if it is older than 2.3.7 (and *especially* if it is older than 2.3.5). – Gord Thompson May 25 '20 at 19:33
  • @DanielW. My unixODBC version is 2.2.14 (too old). i will try to upgrade it and see the result after that – Dont Bullying Me May 26 '20 at 06:28
  • @DanielW. I have searched about latest unixODBC version for CentOS 6.10, i think the latest version is 2.2.14, source here [link](http://rpmfind.net/linux/rpm2html/search.php?query=unixODBC) – Dont Bullying Me May 26 '20 at 07:43
  • @DanielW. : By the way beside installed unixODBC using above command, i also installed `libmdbodbc1` (MDBTools) through this source [link](https://centos.pkgs.org/6/epel-x86_64/mdbtools-libs-0.6-0.7.cvs20051109.el6.1.x86_64.rpm.html), do you think those packages' versions are too old ? – Dont Bullying Me May 26 '20 at 08:16
  • Im out of knowledge at this level but @GordThompson gave you somehint about min version. Maybe upgrading CentOS is also an option. – Daniel W. May 26 '20 at 13:53
  • @DontBullyingMe - unixODBC 2.2.14 is over 11 years old and there have been many bugs fixed since then. If you can't get a newer RPM then you really should try to [install it from source](http://www.unixodbc.org/download.html). – Gord Thompson May 26 '20 at 15:22
  • @DanielW. : I am not being given privilege such as upgrading our CentOS version by my Boss. And i think he would insist about still using our current CentOS version. – Dont Bullying Me May 30 '20 at 03:23
  • @GordThompson Would unixODBC 2.3.7 suit for CentOS 6.10 version ? Based on this [link](http://rpmfind.net/linux/rpm2html/search.php?query=unixODBC) i think it requires CentOS 8, dosen't it ? – Dont Bullying Me May 30 '20 at 03:27
  • @GordThompson : Well, i will try to install unixODBC 2.3.7 in my CentOS 6.10. Hopefully it will work. – Dont Bullying Me May 30 '20 at 03:28
  • By the way should in just install the new one or uninstall the old one and then install new one ? – Dont Bullying Me May 30 '20 at 04:42
  • @GordThompson I have installed _unixODBC 2.3.7_, from the given source but also i have to install `php-odbc` in order to activate my `ODBC` and `PDO_ODBC`. After ran the packages i run `odbcinst -j` command, the command results `unixODBC 2.2.14 DRIVERS............: /etc/odbcinst.ini SYSTEM DATA SOURCES: /etc/odbc.ini FILE DATA SOURCES..: /etc/ODBCDataSources ...` as we can see the _unixODBC 2.2.14_ package version is still running instead of _unixODBC 2.3.7_. This because_unixODBC 2.2.14_ automatically is installed with _pdo-odbc_ by default. – Dont Bullying Me May 30 '20 at 10:05
  • How can i synchronize `php-odbc` with _unixODBC 2.3.7_ instead of 2.2.14 version? – Dont Bullying Me May 30 '20 at 10:07
  • @GordThompson : I have updated the content of the question with more hint. Can you help me sir ? – Dont Bullying Me Jun 02 '20 at 11:01
  • @Daniel W. : I have updated the content of the question, Is the problem my package ? – Dont Bullying Me Jun 02 '20 at 11:04

0 Answers0