<?php
class Group {
private $db, $last_id;
public function __construct() {
$this->db = Database::connect();
}
public function createGroup($admin_id, $name, $description, $type) {
$sql = "INSERT INTO group SET admin_id = ?, name = ?, description = ?, type = ?";
$query = $this->db->prepare($sql);
$result = $query->execute(array($admin_id, $name, $description, $type));
if ($result) {
$this->last_id = $this->db->lastInsertId();
return $this->last_id;
}
return "false";
}
}
?>
这是我的test.php:
<?php
error_reporting(E_ALL);
require "includes/database.php";
require "classes/C_Group.php";
$obj = new Group;
$result = $obj->createGroup(1, "groupName", "groupDescription", "groupType");
echo $result;
?>
表截图:
它总是返回false,我也尝试只在表中插入一个参数(名称),但它再次返回false。并没有插入表中。
答案 0 :(得分:1)
group
是Reserved Words,mysql必须是反引号
$sql = "INSERT INTO `group` SET admin_id = ?, name = ?, description = ?, type = ?";