在 PHP 中,我使用 ODBC 连接到访问数据库。我更新了几个字段没有问题,但我很难让其中两个字段工作。
第一个是访问中的日期/时间类型。
第二个是访问中的备忘录类型。
$mdbFilename = "pathTo.mdb";
$cimdb = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdbFilename", $user, $password);
$sqlInsert = "UPDATE MyTable ";
$sqlInsert .= "SET ";
$sqlInsert .= "Time='07:30:00 AM', ";
$sqlInsert .= "Note='My really long note here...' ";
$sqlInsert .= " WHERE ID=777";
$res = odbc_exec($cimdb, $sqlInsert);
代码产生......
UPDATE MyTable SET Time='07:30:00 AM', Note='My really long note here...' WHERE ID=555
我已经尝试了很多事情,从转换到不同类型的间距/格式。我真的希望以前有人这样做过。
我真正需要知道的是我应该将数据放入什么格式以使访问数据库接受输入?
这是它抛出的错误...
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement., SQL state 37000 in SQLExecDirect in H:\web\count\countInject.php on line 116
SQL statement failed with error: 37000: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.
非常感谢您阅读本文,如果您帮助我,我将倍感感谢 =)
In PHP I am connecting to an access database using ODBC. I update several fields no problem, but I am having a hell of a time getting two of them to work.
First one is of type date/time in access.
Second one is of type memo in access.
$mdbFilename = "pathTo.mdb";
$cimdb = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdbFilename", $user, $password);
$sqlInsert = "UPDATE MyTable ";
$sqlInsert .= "SET ";
$sqlInsert .= "Time='07:30:00 AM', ";
$sqlInsert .= "Note='My really long note here...' ";
$sqlInsert .= " WHERE ID=777";
$res = odbc_exec($cimdb, $sqlInsert);
The code produces.....
UPDATE MyTable SET Time='07:30:00 AM', Note='My really long note here...' WHERE ID=555
I have tried soo many things from casting to converting, to different types of spacing/formatting. I really hope someone has done this before.
What I really need to know is What format do I put the data in to get the access DB to accept the input?
Here is the error it throws...
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement., SQL state 37000 in SQLExecDirect in H:\web\count\countInject.php on line 116
SQL statement failed with error: 37000: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.
Thank you MUCH for reading this through, and double thanks if you help me out =)
发布评论
评论(1)
调试时,我发现将问题分解成尽可能小的块很有帮助。例如,是否可以将日期时间更新与备忘录更新分开,以确保您解决正确的问题。
对于 Access 日期时间值,它需要来自 为 Access SQL 格式化日期时间值 忽略 delphi 位,只需将其转换为 PHP。
对于Memo来说,看起来并没有什么真正的特殊技巧。但是,您可能会在源代码中遇到未转义的括号。
When debugging, I find it helpful to break problems into the smallest chunks possible. For example, is it possible to separate the datetime update from the memo update to ensure you're troubleshooting the right problem.
For Access datetime values, it expects a format of #yyyy-mm-dd HH:MM:SS# from Formatting Date Time Values for Access SQL Ignore the delphi bit, just translate it to PHP.
For Memo, it doesn't look like there's any real special tricks. However, you might be running into an unescaped parenthesis in your source.