phplibrary/src/Database/IdGenerator.php

26 lines
594 B
PHP

<?php
class Database_IdGenerator {
private $db;
function __construct(Database $db) {
$this->db = $db;
}
function isBeforeInsert() {
return false;
}
function isAfterInsert() {
return true;
}
function getId($seq) {
if ($this->db->isPostgres()) {
$result = $this->db->fetchOneArray("SELECT nextval('$seq') AS nextval");
} else {
$result = $this->db->fetchOneArray("SELECT last_insert_rowid() AS nextval");
}
return intval($result['nextval']);
}
}