执行此方法时,数据库返回以下错误: 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();
}
}
}
答案 0 :(得分:1)
NOT
是一个kewyword。
使用"not"
将其用作列名。
答案 1 :(得分:0)
使您自己了解错误的正确代码
class Database{
private $conn;
function __construct() {
$opt = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
$this->conn = new PDO("sqlite:" . DATABASE,NULL,NULL,$opt);
}
function insertRule($ruleName, $isNot, $isInverse){
$ruleId = "ru1";//$this->generateId(RULE);
$q = $this->conn->prepare("INSERT INTO Rule(`ruleId`, `ruleName`, `not`, `inverse`) VALUES(?, ?, ?, ?)");
$q->execute(array($ruleId, $ruleName, $isNot, $isInverse));
}
}
尽管没有特定的insertRule不在数据库类
中