我是第一次使用 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/