运行我的php代码时遇到错误: 关于我在哪里出错的任何想法?
错误说: 致命错误:在第7行的C:\ xampp \ htdocs \ autocomplete \ test.php中的非对象上调用成员函数fetch()
<?php
$database = new SQLiteDatabase('mydatabase.db');
$sql = "SELECT * FROM guests";
$result = $database->queryExec($sql);
while ($row = $result->fetch()){
echo $row['fname']." ".$row['lname'];
echo " say ".substr($row['comments'], 0, 50);
}
?>
答案 0 :(得分:2)
http://www.php.net/manual/en/function.sqlite-exec.php
queryExec(..)
返回布尔值(true
或false
),您无法从结果中获取行。
而是使用query()
函数(http://www.php.net/manual/en/function.sqlite-query.php):
$result = $database->query($sql, SQLITE_ASSOC, $error);
if(!$error && $result != FALSE){
while($row = $result->fetch()){
...
}
} else {
die($result === FALSE ? "Result was false." : $error);
}