简体   繁体   English

SQLite3 :: query语法错误

[英]SQLite3::query syntax error

I have this php code to get data from database 我有这个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>';
}

}
?>

But each time i run this block of code i get these errors 但是每次我运行这段代码时,我都会得到这些错误

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

I have tried all the possible ways i know to fix the issue by editing the query statement but to no avail. 我已尝试通过编辑query语句解决所有已知问题的可行方法,但无济于事。 Please where is the issue from. 请问问题出在哪里。 Any help would be appreciated. 任何帮助,将不胜感激。

You forgot the LIMIT 您忘记了LIMIT

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM