Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Closed Thread
 
Thread Tools Rate Thread
Old 02-20-2008, 03:34 AM   PM User | #31
Ultragames
Regular Coder

 
Join Date: Aug 2002
Location: Oregon, United States of America
Posts: 882
Thanks: 1
Thanked 9 Times in 9 Posts
Ultragames has a little shameless behaviour in the past
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!!
Ultragames is offline  
Old 02-25-2008, 05:09 AM   PM User | #32
bustamelon
Regular Coder

 
Join Date: Mar 2006
Location: Connecticut, USA
Posts: 400
Thanks: 1
Thanked 0 Times in 0 Posts
bustamelon is on a distinguished road
Cool

Quote:
Originally Posted by Fumigator View Post
the author admits it can sometimes fail, but he doesn't care if it occasionally fails for his particular application
Hey y'all. I'm the author of the "solution" in the link, http://blog.jamiedoris.com/geek/560/. I found this thread in my referral logs.

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..
bustamelon is offline  
Old 02-25-2008, 06:48 AM   PM User | #33
Fumigator
Master Coder

 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 6,378
Thanks: 40
Thanked 479 Times in 468 Posts
Fumigator is just really niceFumigator is just really niceFumigator is just really niceFumigator is just really niceFumigator is just really nice
Yay, so now please everyone let this thread die.
__________________
Fumigator is online now  
Old 02-25-2008, 09:29 AM   PM User | #34
idalatob
Regular Coder

 
Join Date: Sep 2007
Location: Grahamstown, South Africa
Posts: 125
Thanks: 5
Thanked 7 Times in 7 Posts
idalatob is an unknown quantity at this point
use last_insert_id() and add 1.
idalatob is offline  
Old 02-25-2008, 12:46 PM   PM User | #35
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,683
Thanks: 2
Thanked 246 Times in 238 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
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. )
Attached Images
 
__________________
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..
CFMaBiSmAd is offline  
Closed Thread

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:08 PM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.