我想将数据插入到SQLite中存储的数据库中,但是,当我将查询传递给pdo时,它会重新运行为false并给出以下消息:致命错误:未捕获的错误:在布尔值上调用成员函数execute()。
这是我的PHP代码:
$ql = "INSERT INTO customer_in (`ledger_id`, `daybook_id`, `description`, `amount`, `date`) VALUES (31, 141, '', 5000, '07/02/2018')";
try {
$con = new Connection();
$conn = $con->connect();
$conn->exec("SET NAMES utf8");
$stmt = $conn->prepare($q1);
$results = $stmt->execute();
}catch (PDOException $e) {
// this is rolback fanction
$conn->rollback();
echo "query is not exe";
}
答案 0 :(得分:1)
这是因为$conn->prepare($q1);
返回了FALSE。问题是您已将查询字符串命名为 $ ql 而不是 $ q1 ,然后在下面的代码中调用了 $ q1 它。
此代码应该有效:
$q1 = "INSERT INTO customer_in (`ledger_id`, `daybook_id`, `description`, `amount`, `date`) VALUES (31, 141, '', 5000, '07/02/2018')";
try {
$con = new Connection();
$conn = $con->connect();
$conn->exec("SET NAMES utf8");
$stmt = $conn->prepare($q1);
$results = $stmt->execute();
}catch (PDOException $e) {
// this is rolback fanction
$conn->rollback();
echo "query is not exe";
}