Example #1
0
 /**
  * Get / allocate / reserve a new id for the current sequence. Important: Getting the next id will fail in case
  * no such sequence exists. Make sure to create one if needed, see {@link create()}.
  *
  * @return int
  * @throws Exception
  */
 public function getNextId()
 {
     $sql = 'UPDATE ' . $this->table . ' SET value = LAST_INSERT_ID(value + 1) WHERE name = ?';
     $result = $this->db->query($sql, array($this->name));
     $rowCount = $result->rowCount();
     if (1 !== $rowCount) {
         throw new Exception("Sequence '" . $this->name . "' not found.");
     }
     $createdId = $this->db->lastInsertId();
     return (int) $createdId;
 }