MDB访问使用php [英] MDB access using php

查看:309
本文介绍了MDB访问使用php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试从php写入.mdb数据库时遇到一些麻烦。

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

数据库有一个名为comments的表,它有3列 id,comment和by。

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";
?>

它从上一页的表单中获取3个值,并应将它们插入数据库,每次获得此错误:

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 />

对我来说,这接缝了MAD,因为我使用一个insert语句,看不到我做错了

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

任何帮助将非常感谢!

感谢

推荐答案

$ odbc_con - > execute(sql); 应为 $ odbc_con - > execute($ sql);

这篇关于MDB访问使用php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆