MDB access using php

夙愿已清 提交于 2020-01-01 19:39:06

问题


I am having a little bit of trouble trying to write to a .mdb database from php.

The database has a table called comments and it has 3 columns "id", "comment" and "by". The code I have is this.

<?php

$count =0;
$db_path = "newsBlog.mdb";
$odbc_con = new COM("ADODB.Connection");
$constr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . $db_path . ";";
$odbc_con -> open($constr);

$sql = "INSERT INTO [comments] VALUES (".$_POST['newsId'].",'".$_POST['comment']."', '".$_POST['by']."')";
echo $sql;
$odbc_con -> execute (sql);

$rs = null;
$conn = null;

echo "done";
?>

It takes 3 values from a form on the previous page and should insert them into the database, except I get this error every time:

<b>Fatal error</b>:  Uncaught exception 'com_exception' with message '&lt;b&gt;Source:&lt;/b&gt; Microsoft OLE DB Provider for ODBC Drivers&lt;br/&gt;&lt;b&gt;Description:&lt;/b&gt; [Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.' in D:\Hosting\7010757\html\users\kinectfashion\postComment.php:20 Stack trace:
#0 D:\Hosting\7010757\html\users\kinectfashion\postComment.php(20): com-&gt;execute('sql')
#1 {main}   thrown in <b>D:\Hosting\7010757\html\users\kinectfashion\postComment.php</b> on line <b>20</b><br />

To me, this seams MAD as I am using an insert statement and cannot see what I am doing wrong!

Any help would be much appreciated!

Thanks


回答1:


$odbc_con -> execute (sql); should be $odbc_con -> execute ($sql);



来源:https://stackoverflow.com/questions/7024754/mdb-access-using-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!