php - sqlite php 获取无法识别的 token : ":" error while inserting and parameterized query

标签 php sqlite

我是第一次使用 sqlite。

准备一个查询字符串,例如

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

它返回“解析错误”。我也尝试过不传递参数化查询,例如

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

并且得到“无法准备语句:1,无法识别的 token :”:“”

知道我哪里做错了吗?

最佳答案

@arnold如果您为此使用 PDO。

前往 prepare 的方法并执行您的查询如下。

$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();

希望这有帮助。

关于php - sqlite php 获取无法识别的 token : ":" error while inserting and parameterized query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16999906/

相关文章:

python - 如何测试一个表是否已经存在?

android - SQLite 异常 : Can't upgrade read-only database from version 1 to 2

android - 由于sqlite问题导致android应用程序崩溃

c++ - 在 SQLite 中迭代一个 select 语句

Jellybean 中的 Android SQLite 数据库事务/锁定更改

php - 通过php控制硬件

PHP - 使用 fwrite 写入特殊字符 - 在记事本中看起来不错,但在浏览器中则错误

php - 如何根据体重选择号码

php - WooCommerce - get_order() 不起作用,它返回零

php - 如何在调查中开发子页面?