0

我有这个代码

if($pdo instanceof PDO){
    $this->last = 'lastInsertId'; 
}
else{
     $this->last = 'insert_id'; 
}

当我在数据库中进行插入查询时,如何获取最后插入的 ID。我试过这样

$this->db->{$this->last}; 

但它没有用。

我在这里先向您的帮助表示感谢。

4

2 回答 2

3

lastInsertId是一种方法,因此您应该将其称为方法,而不是属性/字段。

$this->db->{$this->last}(); 
于 2013-04-11T13:48:24.327 回答
2

尝试call_user_func(Array($this->db,$this->last))

于 2013-04-11T13:45:50.783 回答