无法在SQLite中准备语句

时间:2014-02-25 09:33:24

标签: php sqlite

以下代码有什么问题?

(!)警告:SQLite3 :: prepare()[sqlite3.prepare]:无法准备语句:1,在“:DB_NAME”附近:C:\ xampp \ htdocs \ memo \ DB.php中的语法错误91

调用堆栈

#Time Memory Function Location

1 1.0436 335032 {main}().. \ memo.php:0

2 1.0471 370312备忘录 - > __ construct().. \ memo.php:22

3 1.0524 371112 DB-> addRow().. \ memo.php:17

4 1.0524 371240 prepare().. \ DB.php

/**
 * Add row to DB table.
 * @return bool
 */
public function addRow($idVal, $titleStr, $contentStr){
    $query = "INSERT INTO :DB_NAME VALUES(:ID, :Title, :Content);";
    $stmt = $this->db->prepare($query);
    $stmt->bindValue(":DB_NAME", DB::DB_NAME);
    $stmt->bindValue(':id', $idVal, SQLITE3_INTEGER);
    $stmt->bindValue(":Title", $titleStr, SQLITE3_TEXT);
    $stmt->bindValue(":Content", $contentStr, SQLITE3_TEXT);

    return $stmt->execute();
}

1 个答案:

答案 0 :(得分:6)

您不能在预准备语句中使用表名或列名作为占位符。您只能绑定值。

像这样使用:

$query = "INSERT INTO ". DB::DB_NAME ." VALUES(:ID, :Title, :Content);";