![]() |
|
|
|||||||
![]() |
|
|
Thread Tools | Rate Thread |
|
|
PM User | #31 |
|
Regular Coder ![]() Join Date: Aug 2002
Location: Oregon, United States of America
Posts: 882
Thanks: 1
Thanked 9 Times in 9 Posts
![]() |
I think my last post there says it all. There are a few (only one decent) way to do this given through this thread, but the problem is weather you should or shouldn't do it at all. And in this case, you shouldn't.
__________________
If I'm postin here, I NEED YOUR HELP!! |
|
|
|
|
PM User | #32 | |
|
Regular Coder ![]() Join Date: Mar 2006
Location: Connecticut, USA
Posts: 400
Thanks: 1
Thanked 0 Times in 0 Posts
![]() |
Quote:
![]() To clarify for those that didn't read it, I **used to** use this method in my own personal CMS backend thingamajig, as the ONLY user, and ONLY to get a more or less arbitrary ID that was used in a content preview feature. This ID was used temporarily, then thrown out. It was never referenced in the database at all. So, yes, it's sorta-kinda true that I 'admit it can sometimes fail' (thank you for so barbarously putting words in my mouth ) but it never actually failed in my particular application because I was the sole administrator/author. I took pains to explain this to the naysayers in the article comments, in spite of the fact that I make no claims to offer my snippets as safe or guaranteed in any way, and that I take it for granted (foolish though it may be) that people will RTFM before executing ganked scripts on important data.That said, Fumigator and others are absolutely right -- this is NOT the way to get an ID that will be used in an important app as any kind of future lookup reference. Their suggestion of using last_insert_id() (or some facsimile) in combination with pending/confirmed flag is the proper and safe way, even if it does not actually get the next autoinc without an insert. I wrote that article 5 years ago when I was just a PHP padawan. That particular application is ancient history now, as is just about everything on that dusty old site. But thanks Nancy for standing your ground. You were right too -- the OP did not specify the intent, so this was a perfectly legit answer to the Q. Hope that helps put this "controversy" to bed .
Last edited by bustamelon; 02-25-2008 at 06:31 AM.. |
|
|
|
|
|
PM User | #35 |
|
Senior Coder ![]() Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,683
Thanks: 2
Thanked 246 Times in 238 Posts
![]() ![]() ![]() ![]() |
idalatob, firstly, Fumigator suggested to not continue adding comments to this thread.
Secondly, last_insert_id() is only available after an INSERT query has been executed in the same script. However if you have inserted the record to establish the ID (which is the correct solution to getting a known ID and has already been stated here), there is no need to add 1 to it. Also, adding one to the last ID serves no useful purpose as concurrent visitors will make the number you come up with incorrect and unusable for any purpose except to display it (which has also been stated here.) Could a moderator please close this thread (too bad we don't have a beating a dead horse smiley. )
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you. Last edited by CFMaBiSmAd; 02-25-2008 at 12:49 PM.. |
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Rate This Thread | |
|
|