2015-10-26 98 views
0
<?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:PDO總是返回false

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

groupReserved Words是MySQL是必須在反引號

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