<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Building a Better Board Banner System Part II: Using LAST_INSERT_ID()</title>
	<atom:link href="http://www.phpbbdoctor.com/blog/2008/08/29/building-a-better-board-banner-system-part-ii-using-last_insert_id/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phpbbdoctor.com/blog/2008/08/29/building-a-better-board-banner-system-part-ii-using-last_insert_id/</link>
	<description>Your premium source for custom modification services for phpBB</description>
	<lastBuildDate>Wed, 11 Jan 2012 20:39:04 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Dog Cow</title>
		<link>http://www.phpbbdoctor.com/blog/2008/08/29/building-a-better-board-banner-system-part-ii-using-last_insert_id/comment-page-1/#comment-2806</link>
		<dc:creator>Dog Cow</dc:creator>
		<pubDate>Tue, 02 Sep 2008 14:51:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpbbdoctor.com/blog/?p=243#comment-2806</guid>
		<description>Thanks for the info; I think it&#039;s back to plan 2 for me. :(</description>
		<content:encoded><![CDATA[<p>Thanks for the info; I think it&#8217;s back to plan 2 for me. <img src='http://www.phpbbdoctor.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Rathbun</title>
		<link>http://www.phpbbdoctor.com/blog/2008/08/29/building-a-better-board-banner-system-part-ii-using-last_insert_id/comment-page-1/#comment-2802</link>
		<dc:creator>Dave Rathbun</dc:creator>
		<pubDate>Sat, 30 Aug 2008 21:48:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpbbdoctor.com/blog/?p=243#comment-2802</guid>
		<description>The brute-force way would be to run a query like they do when adding a new user to phpBB2. You get the max value and increment by one. However, that&#039;s not suitable for high-volume tables. I don&#039;t think the LAST_INSERT_ID() function is going to help because it preserves a value that was just processed, rather than anticipating something that has yet to happen.</description>
		<content:encoded><![CDATA[<p>The brute-force way would be to run a query like they do when adding a new user to phpBB2. You get the max value and increment by one. However, that&#8217;s not suitable for high-volume tables. I don&#8217;t think the LAST_INSERT_ID() function is going to help because it preserves a value that was just processed, rather than anticipating something that has yet to happen.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dog Cow</title>
		<link>http://www.phpbbdoctor.com/blog/2008/08/29/building-a-better-board-banner-system-part-ii-using-last_insert_id/comment-page-1/#comment-2801</link>
		<dc:creator>Dog Cow</dc:creator>
		<pubDate>Sat, 30 Aug 2008 21:28:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpbbdoctor.com/blog/?p=243#comment-2801</guid>
		<description>I should have explained myself better. You didn&#039;t answer my question (my fault).

Ok, what I want to know is if there is an easy way to find out what the next auto_increment is going to be &lt;i&gt;before&lt;/i&gt; the row is inserted/updated.

I need to use that next auto_increment number to influence another decision in the code. For example, if the index will be greater than 100, then the number will be 2, else if it is less than 100, the number will be 1.

I know there&#039;s a not-so-elegant way where you can query the table info (this is how phpMyAdmin does it, because it will show the next auto_increment value).

Can this be done in one query? If not, my plan 2 is to use two queries to do the same thing.</description>
		<content:encoded><![CDATA[<p>I should have explained myself better. You didn&#8217;t answer my question (my fault).</p>
<p>Ok, what I want to know is if there is an easy way to find out what the next auto_increment is going to be <i>before</i> the row is inserted/updated.</p>
<p>I need to use that next auto_increment number to influence another decision in the code. For example, if the index will be greater than 100, then the number will be 2, else if it is less than 100, the number will be 1.</p>
<p>I know there&#8217;s a not-so-elegant way where you can query the table info (this is how phpMyAdmin does it, because it will show the next auto_increment value).</p>
<p>Can this be done in one query? If not, my plan 2 is to use two queries to do the same thing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Rathbun</title>
		<link>http://www.phpbbdoctor.com/blog/2008/08/29/building-a-better-board-banner-system-part-ii-using-last_insert_id/comment-page-1/#comment-2800</link>
		<dc:creator>Dave Rathbun</dc:creator>
		<pubDate>Fri, 29 Aug 2008 21:10:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpbbdoctor.com/blog/?p=243#comment-2800</guid>
		<description>Dog Cow, if you look at the code you&#039;ll see that I&#039;m using the LAST_INSERT_ID() to track an update. :) From what I remember reading, it captures the expression result, it&#039;s not really tied to the auto-increment value despite what it sounds like.

An auto-increment is already handled separately; there is no danger of getting someone else&#039;s increment value in your code even if you sleep for a few minutes before going back to get it. The power of the LAST_INSERT_ID() in my case was I can run an update and capture the result of the update all in one statement. The code was:

&lt;pre&gt;UPDATE phpbb_views
SET view_ctr = LAST_INSERT_ID(view_ctr+1) ;&lt;/pre&gt;

So what that does is generate a numeric value by incrementing the current value of view_ctr by adding one, capture that number in a register or something somewhere, then perform the update. Then when I request the LAST_INSERT_ID() value I retrieve that same value, even if 20 more updates have happened in between the update and my request. And I didn&#039;t have to lock the row or table in order to manage that.</description>
		<content:encoded><![CDATA[<p>Dog Cow, if you look at the code you&#8217;ll see that I&#8217;m using the LAST_INSERT_ID() to track an update. <img src='http://www.phpbbdoctor.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  From what I remember reading, it captures the expression result, it&#8217;s not really tied to the auto-increment value despite what it sounds like.</p>
<p>An auto-increment is already handled separately; there is no danger of getting someone else&#8217;s increment value in your code even if you sleep for a few minutes before going back to get it. The power of the LAST_INSERT_ID() in my case was I can run an update and capture the result of the update all in one statement. The code was:</p>
<pre>UPDATE phpbb_views
SET view_ctr = LAST_INSERT_ID(view_ctr+1) ;</pre>
<p>So what that does is generate a numeric value by incrementing the current value of view_ctr by adding one, capture that number in a register or something somewhere, then perform the update. Then when I request the LAST_INSERT_ID() value I retrieve that same value, even if 20 more updates have happened in between the update and my request. And I didn&#8217;t have to lock the row or table in order to manage that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dog Cow</title>
		<link>http://www.phpbbdoctor.com/blog/2008/08/29/building-a-better-board-banner-system-part-ii-using-last_insert_id/comment-page-1/#comment-2798</link>
		<dc:creator>Dog Cow</dc:creator>
		<pubDate>Fri, 29 Aug 2008 20:37:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpbbdoctor.com/blog/?p=243#comment-2798</guid>
		<description>I think this will prove useful for a project I&#039;m working on.

Can I query SELECT LAST_INSERT_ID() ; without having run an INSERT?

Ie, can I just do SELECT LAST_INSERT_ID() FROM phpbb_tablename to get the next auto-index?

Does that work?</description>
		<content:encoded><![CDATA[<p>I think this will prove useful for a project I&#8217;m working on.</p>
<p>Can I query SELECT LAST_INSERT_ID() ; without having run an INSERT?</p>
<p>Ie, can I just do SELECT LAST_INSERT_ID() FROM phpbb_tablename to get the next auto-index?</p>
<p>Does that work?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

