当我执行这个方法时,数据库返回如下错误: 1. 数据库没有问题,检查所有列名都匹配。代码在语法上也是正确的。我有另一种实现相同的方法,只是表名和列名不同。
Fatal error: Call to a member function execute() on a non-object in C:\xampp\htdocs\timetable-generator-v2\inout.php on line 173
$db = new Database();
$db->insertRule("something", NULL, NULL);
class Database{
private $conn;
function __construct() {
try {
$this->conn = new PDO("sqlite:" . DATABASE);
} catch (PDOException $e) {
echo $e->getMessage() . " - failed on: Database->__construct()";
die();
}
}
function insertRule($ruleName, $isNot, $isInverse){
$ruleId = "ru1";//$this->generateId(RULE);
try {
$q = $this->conn->prepare("INSERT INTO Rule(ruleId, ruleName, not, inverse) VALUES(?, ?, ?, ?)");
$q->execute(array($ruleId, $ruleName, $isNot, $isInverse));
} catch (PDOException $e) {
echo $e->getMessage() . " - failed on: Database->insertRule()";
die();
}
}
}