/** * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. * @param string optional sequence name * @return int * @throws Exception */ public function getInsertId($sequence = NULL) { $this->connected || $this->connect(); $id = $this->driver->getInsertId($sequence); if ($id < 1) { throw new Exception('Cannot retrieve last generated ID.'); } return (int) $id; }