SQLite3 ::查询语法错误

时间:2017-06-15 13:33:25

标签: php sqlite

我有这个PHP代码来从数据库中获取数据

<?php
require_once ("db.php");
$db = new MyDb();

if (isset($_POST['limit']) && isset($_POST['start'])) {

$start = $_POST["start"];
$limit = $_POST["limit"];

$query =<<<EOF
SELECT * FROM questions ORDER BY quiz_id DESC '$start', '$limit';
EOF;

$result = $db->query($query);

while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
  echo 'div class="quesbox">
  <div class="questitle">
      <h2>'.$row["question"].'</h2>
  </div>
  <div class="quesanswer">'.$row["answer"].'</div>
    <div class="quesdatetime"><img src="images/questime.png" alt="export question">'.$row["date"].'</div>
  </div>';
}

}
?>

但是每次运行这段代码我都会遇到这些错误

Warning: SQLite3::query(): Unable to prepare statement: 1, near "'0'": syntax error in C:\xampp\htdocs\xport\searchfetch.php on line 14

Fatal error: Call to a member function fetchArray() on a non-object in C:\xampp\htdocs\xport\searchfetch.php on line 16

我已经尝试了所有可能的方法,通过编辑query语句来解决问题,但无济于事。请问问题在哪里。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

您忘记了LIMIT

$query =<<<EOF
SELECT * FROM questions ORDER BY quiz_id DESC LIMIT '$start', '$limit';
EOF;