Re: DB class, MySQL and nextId()
| From: | Chris Boget | Date: | Thu, 15 Apr 2004 21:15:29 +0000 |
| Subject: | Re: DB class, MySQL and nextId() | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-11887@lists.php.net to get a copy of this message | ||
> You call nextId() before an insert and use this for your next insert. You
> don't need last_insert_id because you already have the id from nextId().
Except that this doesn't help when already you have a table with 1000
records (numbered 1 - 1000). You create a new sequence, get the nextId()
and guess what? The value that's returned is "1". I try to use that value
in
my INSERT statement and guess what? My query fails because it's trying
to insert a duplicate value.
In order to start using PEAR DB on a system that's already up and running,
you'd have to create a sequence table for *every single* other table that
is using an auto_increment field and seed the "id" column to the current
value of the auto_increment field. Then, you would need to convert *every
single* bit of code that is inserting into those tables to use PEAR and
the new sequence table. That sounds like a pretty massive overhaul if
you wanted to use PEAR DB in one small function/class that might run
INSERT queries. That doesn't sound very user friendly nor does it sound
worthwhile to start using PEAR DB late in the game (at least for systems
using MySQL).
Chris