Re: Adding Records & Capture The New Record ID

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

 



tedd wrote:
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.

Your suggestion has to be done using a unique field (marked as such in the db) otherwise it won't work.

If it's not -

Person a signs up with email@xxxxxxxxxxx

Before you are able to fetch the result (which is possible in a high traffic site), person b also signs up with email@xxxxxxxxxxx

Going back to person a, when you fetch, you get record #2 instead of #1.

They are not the same record.


Not a great example because you probably wouldn't have people using the same address from different locations, but it's just to demonstrate the problem of doing it this way.

--
Postgresql & php tutorials
http://www.designmagick.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