Subject Re: [firebird-php] auto increment last insert
Author Lester Caine
FIRST - will people please hack the replies. They are getting very long ;)

Second - I think I've been passing duff info. You get used to ADOdb's
way of doing things.

ibase_execute returns a result set
ibase_query returns a result set identifier

I'm using the Execute rather than Query and forgetting that

Darren Thompson wrote:

> I think you is not pretending but i think you should read the php manual.
> Clarion yeah i know a little never thought it was still being used.
>
> looking at your prob your code is messy
>
> Function GetId() {
> $qry = 'SELECT gen_id('GEN_USERS',1) AS Id from RDB$DATABASE';
> $res = ibase_query($qry);
> while ($resrow = ibase_fetch_row($res)) {
> $id = $resrow[0];
> }
> return($id);
> }
>
>
> //use
> $variable = GetId();
>
> use this function to get a gen id

ADOdb equivalent creates the generator if it does not exist -
function GenID($seqname='adodbseq',$startID=1)
{
$getnext = ("SELECT Gen_ID($seqname,1) FROM RDB\$DATABASE");
$rs = @$this->Execute($getnext);
if (!$rs) {
$this->Execute(("INSERT INTO RDB\$GENERATORS (RDB\$GENERATOR_NAME)
VALUES (UPPER('$seqname'))" ));
$this->Execute("SET GENERATOR $seqname TO ".($startID-1).';');
$rs = $this->Execute($getnext);
}
if ($rs && !$rs->EOF) $this->genID = (integer) reset($rs->fields);
else $this->genID = 0; // false

if ($rs) $rs->Close();

return $this->genID;
}


--
Lester Caine
-----------------------------
L.S.Caine Electronic Services