Ok, I am trying out the PEAR DB to see if I want to use it for my whole site. In my site, I have quite a few M:N M:1 relationships, in those cases, I first insert one query, and then get that ID (from an auto_increment key field) and use it in the next query to establish the relationship.

Now... in PEAR DB .. the nextID is emulated by creating a sequence table...thats ok, I guess.. but say, I delete the last record in a table, then insert a new one....the nextID from PEAR DB is going to be off, because it doesn't know I deleted a record?

See what I mean? any way around this?

Thanks

    Actually, the NextID will not be off since the whole purpose of the auto-increment (or sequence, or whatever) is NOT to generate an unbroken sequence, but to guarantee UNIQUE identifiers.

      It doesn't matter that the next id will be 'off'. Primary keys should always have no meaning to the data other than to reference the row. Having spaces in your key sequence should never be a problem if you do not use a special meaning for the primary key.

        I am making a discussion board in which I am using the same table for the topics as well as the posts. So, a topic would have the same number for the key, root_key

        So, I'd have to insert the data, and then get the ID ... and insert it for the root_key

        Should I not set auto_increment in my table when I am using PEAR DB? ... and just use $db->nextID to get a number for the key and insert it myself?

        Thanks

          Should I not set auto_increment in my table when I am using PEAR DB? ... and just use $db->nextID to get a number for the key and insert it myself?

          Yes. auto_increment is not compatable across databases so to make your PEAR app unassuming, you should use DB::nextID

            Write a Reply...