PHP update instruction error for unixODBC

I am using Ubuntu + php + unixodbc + mdbtools to work with a .mdb file.
Every thing (connection + choice) works well, but insert or update.
My code looks something like this:

$mdbConnection = new \PDO("odbc:mdbdriver",$user , $password , array('dbname' =>$FileName) ); $SelectResult = $mdbConnection->query("Select * from Zone"); $UpdateResult = $mdbConnection->query("Update Zone Set ShahrCode = 99"); 

$SelectResult returns the correct result, and the second causes an error causing an apache error for segfault.
I am testing it with the isql.Running Select command successfully, but Update is not.

 #isql mdbdriver +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ SQL>Update Zone Set ShahrCode = 99 Error at Line : syntax error near Update syntax error near Update Got no result for 'Update Zone Set ShahrCode = 99' command [08001][unixODBC]Couldn't parse SQL [ISQL]ERROR: Could not SQLExecute 

Or

 SQL> Update [Zone] Set ShahrCode = 99 Error at Line : syntax error near Update syntax error near Update Got no result for 'Update [Zone] Set ShahrCode = 99' command [ISQL]ERROR: Could not SQLExecute 

How do I fix this error? Thank you all

+1
source share
2 answers

Finally, I find a solution:
mdbtools cannot write mdb files.

MDB Tools currently only supports reading for Access 97 (Jet 3) and Access to 2000/2002 (Jet 4) formats. Recording support is currently in progress and the first cut is expected to be included in the 0.6 release.

Using a simple compiled java application is our solution.

  • Create a simple java project with the Jackcess library.
  • Enable CLI options for your Java application and do what you want using the mdb file.
    • You can even get the path to the mdb file with CLI parameters.
  • Compile java project.
  • In PHP you can use exec('cd path/to/javaproject;java -cp . YourJavaProject "mdbfilepath" "insert|update|or select"',$output);
0
source

Personally, I would not spend much time trying to get PHP + mdb_tools + unixODBC to work together reliably. I tried several times and was unsuccessful, despite all my efforts.

My recommendations:

  • If storing your data in an Access.mdb file is a strict requirement, then you need to assume that Windows computers are involved in the project. In this case, I suggest you run your PHP code on a Windows machine and use COM_DOTNET to manage the Access database (via ODBC Windows using ADODB.Connection and related objects).

  • If your PHP code on Linux is a strict requirement, then there is a strong point for moving your data from Access.mdb to another database that works best with PHP. (MySQL will be one of the most common options.)

  • If both 1. and 2. are stringent requirements, perhaps the best option would be to move the .mdb file to the Windows machine and use ODBTP to manipulate the .mdb file from the PHP code running on the Linux machine.

+1
source

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


All Articles