将变量更新为sqlite

时间:2012-07-08 07:44:13

标签: sqlite

我正在尝试将变量更新到sqlite3数据库中。该查询在sqlite浏览器中工作,但是当我想通过我的网页更新时,它给出了'致命错误:在非对象上调用成员函数execute()'。

Code:
$DB = new PDO('sqlite:database/Sample.sqlite3');
$No = 1;
$Name = 'John';
$RecordNo = 2;
$statement ="update Sample set No =".$No.", Name='".Name."', Date='2012-05-14' where RecordNo=".$RecordNo;
$update = $DB->prepare($statement);
$update->execute();

致命错误发生在'$ update-> execute();'的声明中它应该执行的地方,因为没有语法错误或代码。请建议。

1 个答案:

答案 0 :(得分:1)

替代......

<?php
$DB = new PDO('sqlite:database/Sample.sqlite3');
/* Execute a prepared statement by passing an array of insert values */
$No = 1;
$Name = 'John';
$RecordNo = 2;
$sth = $dbh->prepare('update sample set No=? Name=? Date='2012-05-14' where Recordno =?');
$sth->execute(array($No, $Name,$RecordNo));
?>