Re: Insert ID
| From: | Patrik Wallstrom | Date: | Thu, 15 Aug 2002 19:57:02 +0000 |
| Subject: | Re: Insert ID | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-2126@lists.php.net to get a copy of this message | ||
On Thu, 15 Aug 2002, Markus Wolff wrote:
> > You people may have heard this one many times but here goes.
> >
> > Whats the easiest and most database independent way of getting an id back
> > from an insert you have just performed using Pear.
>
> "The easiest and most database independent way" would be _not_ to get an
> id _back_, but to get the next id for your insert _before_ it is
> performed. To achieve this, use sequences instead of auto_increment
> fields. PEAR::DB emulates sequences for databases that don´t support
> them natively (like MySQL).
That would be no good if for example you insert something in a web
application, and the next step would be to display that record with a
redirect. The semi-bad way to solve this without getting the inserted
id would be to use an already known unique id, but that wouldn't be
good code.
--
patrik_wallstrom->foodfight->pawal@blipp.com->+46-709580442