I've developed a web application using php4 and interbase. I developed the database using IBconsole. The web application is almost complete but I\'m having some trouble with the admin pages which allow the administrator to add data to the database.

Interbase does not support auto_increment. When I entered the initial information into the tables I used the IBConsole. How do I get the primary key values to auto increment when an entry is made from the web site?

Tania

    Hello,

    I had the same situation, and implemented some kind of autoincrement myself.
    Take a look to this:

    // autoincrement KEYINDEX
    $sth = ibase_query($dbh,'SELECT MAX(KEYINDEX) FROM ADDRESS');
    settype($NEWKEYINDEX,'integer');
    $NEWKEYINDEX=1;
    while ($row = ibase_fetch_row ($sth))
    {
    $NEWKEYINDEX = $row[0] + 1;
    }
    ibase_free_result($sth);

    (more of this here www.mind.lu/~yg/i-man/)

    Then, I issue a second query, and use the value
    of $NEWKEYINDEX for my primary key.

    I know there is a little risk of failure when two users would execute this page at
    the same time, but I use this in only two
    places in my application, and I found no
    other simple solution.
    You could also do it with a stored procdure/trigger in Interbase.
    There is a powerful ibsupport mailing list (ib-support@yahoogroups.com)

    yves

      Hi I'm not familiar with interbase but the method I used on other dbes is:
      create a table with the max value of the column you want for your Pri key.
      When you add a record lock the table with the max value, then fetch the value+1 for your new key value, then store the new max value in the table and unlock the table. You should lock the table so that in will not change from the time you fetch the value and store the record.
      Ray

        Write a Reply...