UnixODBC + mdbTools + PHP

I need to connect a PHP script on a LAMP server (Linux Ubuntu 12.10, Apache 2, MySQL 5, PHP 5.3) to an Access MDB database (version 2003).

1. install unixODBC and driver

Ubuntu 12.10 ships with unixodbc 2.2.14 ( http://packages.ubuntu.com/quantal/unixodbc ). The installation was simple: apt-get install unixodbc libmdbodbc1 php5-odbc. So I have unixODBC with the mdbTools driver and the PHP ODBC feature.

I edited the /etc/odbcinst.ini file using the mdbtools driver:

[MDBToolsODBC] Description = MDBTools Driver Driver = libmdbodbc.so.1 

I edited the /etc/odbc.ini file using the Access data source:

 [FormPulmo] Description = FormulariCDRPulmo Driver = MDBToolsODBC Servername = localhost Database = /mnt/svrfit/cdr/bd_pulmo_hardlink.mdb UserName = Password = port = 5432 

Finally, I tested the shell and worked:

 > isql -v formpulmo Connected! 

2. Connection to PHP

With PHP initialy, everything works fine:

 $link = odbc_connect ('formpulmo',"",""); $res = odbc_exec ($link,"SELECT * FROM exampleTable"); 

The first problem was trying to access tables with spaces in their names. Example: "Example table." On Windows, I have to set this between the brackets ([Example table]), but this did not work. Finally, I found a solution:

 $res = odbc_exec ($link,"SELECT * FROM \"example Table\""); 

Prior to this solution, all browser responses attempting to execute odbc_exec were "Error 324 (net :: ERR_EMPTY_RESPONSE)"

3. Problems with PHP!

But now I'm stuck in the UPDATE syntax. Normal query:

 $res = odbc_exec ($link,"UPDATE [Registre cancer de pulmo] SET CIP = 'example' WHERE CIP = 'example'"); 

Browser response: "Error 324 (net :: ERR_EMPTY_RESPONSE)" (in Firefox: "Connection was reset").

3.1. Trial solutions

 UPDATE \"Registre cancer de pulmo\" SET CIP = 'example' WHERE CIP = 'example' UPDATE \"Registre cancer de pulmo\" SET \"CIP\" = 'example' WHERE \"CIP\" = 'example' UPDATE {Registre cancer de pulmo} SET {CIP} = 'example' WHERE {CIP} = 'example' 

Connection with different cursors:

 odbc_connect ($odbcFormPulmo,"","",SQL_CUR_USE_ODBC); odbc_connect($odbcFormPulmo,"","",SQL_CUR_USE_DRIVER); 

I do not know what else I can try: - (

+4
source share
1 answer

A few weeks ago, in response to this question, I did some testing on an installation almost identical to yours (Ubuntu 12.04 instead of 12.10), and found that I could not get mdbtools to work at all. I understand that some people can sometimes relate to their work, but IMO mdbtools not reliable enough for use in production.

In my answer to this question, I recommended exploring ODBTP as an alternative. This is a free TCP / IP (GPL) protocol that allows you to transfer requests to a Windows computer, which then sends the request through its ODBC driver and sends the results back to you. I have used it several times in the past and it worked very well.

+2
source

Source: https://habr.com/ru/post/1484373/


All Articles