Re: Adding Records & Capture The New Record ID

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 1:36 AM +0000 2/8/09, Ashley Sheridan wrote:
On Sat, 2009-02-07 at 15:26 -0500, tedd wrote:
 > That's one way, to use "mysql_insert_id" (probably the best).

 But another is simply to read back in the record you just created and
 check the $row['id']. That's the way I do it sometimes.

 Cheers,

 tedd
 --
 -------
 http://sperling.com  http://ancientstones.com  http://earthstones.com

How do you plan on reading back the row if you don't use the
mysql_insert_id value? For most cases, it's not enough to read back the

 Ash:

As I said *sometimes* and I also said *using using "mysql_insert_id" is probably the best*.

But to answer your question, there are records that are unique (or should be) without knowing the record ID. Such as those records having a certain logon and password, or a specific email address. Those data are supposed to be an unique as the record's ID, right?

For example, I have one scheme to gather email addresses -- and an email address IS unique. While two people can share one email address, it makes no difference to a mailing list and thus the record's ID and email address are equally unique and records can be found just as easily using either. In fact, while it may be a good idea to have a record ID for other functions, an ID field is not even required if all the table is doing is providing email addresses -- simply index email address field.

Also, if you have an authorization scheme, then the logon and password coupling are supposed to be as unique as a record ID, right? Again, either the record ID or the logon/password coupling can be used to find the record.

As I will say again, using "mysql_insert_id" is probably the best -- however -- it's just not the only way. If for no other person than me, sometimes to show what the code is doing is more obvious by finding the record you just created than by using "mysql_insert_id".

Cheers,

tedd


--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux