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: - (