[英]pdo always return false
<?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 : 这是我的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. 它总是返回false,我也尝试仅将一个参数(名称)插入表中,但它再次返回false。 And nothing inserted in table.
表格中没有任何内容。
group
是保留字是mysql必须在反引号中
$sql = "INSERT INTO `group` SET admin_id = ?, name = ?, description = ?, type = ?";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.