RE: [PEAR] DB class, MySQL and nextId()
| From: | Torsten Roehr | Date: | Thu, 15 Apr 2004 21:37:26 +0000 |
| Subject: | RE: [PEAR] DB class, MySQL and nextId() | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-11890@lists.php.net to get a copy of this message | ||
> 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.
No, only for tables where you need the id after the insert (see below).
> 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).
I think the benefit is worth the work. And you only need a sequence for
those tables that are referenced as foreign keys in other tables (where you
need the id for the reference insert). You don't need it for every table.
E.g. if you have a child and a parents table you only need a sequence for
the parents table because usually you don't need the id from the child
insert.
Just call nextId() once for every table that is referenced somewhere as a
foreign key and PEAR::DB will set up a sequence table for each of these
tables. Then manually update the values in the sequence tables to your
respective latest id. Unless you have hundreds of tables that are referenced
in other tables as foreign keys this should be done in a few minutes' work.
What do you think?
Torsten
>
> Chris
>
> --
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>