<?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";
}
}
?>
Here is my 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;
?>
Table screenshot :
It always returns false, i also tried insert only one parameter (name) into table, but it return false again. And nothing inserted in table.
group
是保留字是mysql必须在反引号中
$sql = "INSERT INTO `group` SET admin_id = ?, name = ?, description = ?, type = ?";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.