pdo总是返回false

时间:2015-10-26 13:15:46

标签: php mysql pdo

<?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;
?>

表截图:

enter image description here

它总是返回false,我也尝试只在表中插入一个参数(名称),但它再次返回false。并没有插入表中。

1 个答案:

答案 0 :(得分:1)

groupReserved Words,mysql必须是反引号

 $sql = "INSERT INTO `group` SET admin_id = ?, name = ?, description = ?, type = ?";