Re: [Phplib-users] nextid - how does it work?
Brought to you by:
nhruby,
richardarcher
|
From: Peter T. <pte...@te...> - 2003-07-16 22:51:45
|
There is similar functionality in MySQL.
The equivalent for the PostgreSQL /Oracle sequence is the AUTO_INCREMENT
column type. (Although the implementation works slightly different).
The LAST_INSERT_ID() function is tied to AUTO_INCREMENT and could be
helpful building a 'next sequence' mechanism with MySQL. Check the MySQL
docs for the specifics.
If your goal is building a database independent solution, I would opt for
the PHPLIB solution.
Peter
At 00:29 17-07-2003, Nathaniel Price wrote:
>----- Original Message -----
>From: "Liberty Young" <li...@em...>
>To: "Neha Mathur" <ne...@sp...>
>Cc: <php...@li...>
>Sent: Wednesday, July 16, 2003 3:02 PM
>Subject: Re: [Phplib-users] nextid - how does it work?
>
>
> > I can't answer your question..though i do have a few comments.
> >
> > Why are you inputting primary keys? Few RDBMS don't have the option to
> > auto-increment your primary key field. I rarely find myself in a
> > situation where i'm inputing the value for a primary key field. Foreign
> > keys, yes, but never primary keys!!! If you're inserting a new record,
> > let your server do that for you. I _know_ MySQL will do that for you
>
>There are some instances where it is useful or even necessary to know ahead
>of time what primary key will be assigned to a given record when it is
>inserted. This function provides one means of doing that.
>
>I don't know about MySQL, but in PostgreSQL you can use built-in sequences
>and find out the primary key that will be used by querying the database
>using "select nextval('sequence_name');", however, since this is not part of
>the SQL standard, it is likely not portable to other databases. This method
>would be portable across all the databases PHPlib supports. It also results
>in a bit cleaner code; using PostgreSQL, I have to do this to get a primary
>key from the database:
>
>$db->query("select nextval('sequence_name');");
>$db->next_record();
>$my_id = $db->f('nextval');
>
>whereas with PHPlib it would become:
>
>$my_id = $db->nextid('sequence_name');
>
>_________________________________
>Nathaniel Price <np...@te...>
>Webmaster
>
>
>
>-------------------------------------------------------
>This SF.net email is sponsored by: VM Ware
>With VMware you can run multiple operating systems on a single machine.
>WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
>same time. Free trial click here: http://www.vmware.com/wl/offer/345/0
>_______________________________________________
>Phplib-users mailing list
>Php...@li...
>https://lists.sourceforge.net/lists/listinfo/phplib-users
----------
TERIS Information Services BV
Peter Termaten Phone: +31 23 565 2682
Aagje Dekenstraat 43 Fax: +31 23 565 2676
2135 RJ Hoofddorp Mobile: +31 653 65 8686
www.teris.nl
----------
|