问题
I'm using Ubuntu+php+unixodbc+mdbtools for working with .mdb file.
Every thing(connection+select) works good, but Insert or Update statements.
My code is 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 correct result, but the second one throws an error that cause apache to segfault error.
I test it with isql command.Running Select statement is successful 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 should I fix this error ? Thanks all
回答1:
Personally, I wouldn't spend a lot of time trying to get PHP + mdb_tools + unixODBC to work together reliably. I have tried on several occasions and have been quite unsuccessful despite my best efforts.
My recommendations would be:
If maintaining your data in an Access .mdb file is a firm requirement then one must assume that Windows machines are involved in the project. In that case I would suggest that you run your PHP code on a Windows machine and use COM_DOTNET to manipulate the Access database (via Windows ODBC using
ADODB.Connection
and related objects).If running your PHP code on Linux is a firm requirement then there is a strong case for moving your data from the Access .mdb into some other database that works better with PHP. (MySQL would be one of the more common choices.)
If both 1. and 2. are firm requirements then perhaps the best option might be to move the .mdb file to a Windows machine and use ODBTP to manipulate the .mdb file from PHP code running on the Linux machine.
回答2:
At last I found a solution :
mdbtools can not write to mdb files yet.
MDB Tools currently has read-only support for Access 97 (Jet 3) and Access 2000/2002 (Jet 4) formats. Write support is currently being worked on and the first cut is expected to be included in the 0.6 release.
Using simple compiled java application is our solution.
- Create a simple java project with Jackcess library.
- Enable CLI params for java application and do what you want with
mdb file.
- You can even get mdb file path with CLI params.
- Compile java project.
- In PHP you can use
exec('cd path/to/javaproject;java -cp . YourJavaProject "mdbfilepath" "insert|update|or select"',$output);
来源:https://stackoverflow.com/questions/24342165/unixodbc-php-update-statement-error