Sqlite PHP无法识别令牌:"; "插入和参数化查询时出错


sqlite php getting unrecognized token: ":" error while inserting and parameterized query

我第一次使用sqlite。

准备像

这样的查询字符串
$articleInsertQuery = "INSERT INTO Articles VALUES (?, ?, ?, ?, ?)", ($i, $title, $content, $date, 93,);

返回"Parse error"。我也尝试过不传递参数化查询,如

$articleInsertQuery = "INSERT INTO Articles VALUES ($i, $title, $content, $date, 93)";

得到"Unable to prepare statement: 1, unrecognized token: ":" "

知道我在哪里做错了吗?

@arnoldIf

准备和执行查询的方法如下:

$dbObject = new PDO('sqlite:sqlitedb');// NEW LINE
$articleInsertQuery = "INSERT INTO Articles VALUES (?, ?, ?, ?, ?)";
$query = $dbObject->prepare($articleInsertQuery);
$query->execute(array($i, $title, $content, $date, 93));
编辑:

参见sqlite3 prepare.

$articleInsertQuery = "INSERT INTO Articles VALUES (:i, :title, :content, :date, :int)";
$query = $dbObject->prepare($articleInsertQuery);
$query->bindValue(':i', $i, SQLITE3_INTEGER);
$query->bindValue(':title', $title, SQLITE3_TEXT);
$query->bindValue(':content', $content, SQLITE3_TEXT);
$query->bindValue(':date', $date, SQLITE3_TEXT);
$query->bindValue(':int', 93, SQLITE3_INTEGER);    
$result = $query->execute();