<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>innerlogic &#187; MySQL</title>
	<atom:link href="http://blog.innerlogic.gr/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.innerlogic.gr</link>
	<description>random stuff about technology, programming, digital media</description>
	<lastBuildDate>Tue, 10 Jan 2012 01:50:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MySQL: Get next auto increment value</title>
		<link>http://blog.innerlogic.gr/mysql-get-next-auto-increment-value/</link>
		<comments>http://blog.innerlogic.gr/mysql-get-next-auto-increment-value/#comments</comments>
		<pubDate>Tue, 29 May 2007 22:47:43 +0000</pubDate>
		<dc:creator>leo</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://blog.innerlogic.gr/mysql-get-next-auto-increment-value/</guid>
		<description><![CDATA[Tweet Recently, I needed to get the auto increment value for the next inserted row in a MySQL table.  Generally, this is not a good idea and you should stop reading right now. You may end up with duplicate entries (&#8230;)</p><p><a href="http://blog.innerlogic.gr/mysql-get-next-auto-increment-value/">Read the rest of this entry &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: left; margin-bottom: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fblog.innerlogic.gr%2Fmysql-get-next-auto-increment-value%2F" class="twitter-share-button" data-url="http://blog.innerlogic.gr/mysql-get-next-auto-increment-value/" data-count="vertical" data-via="" data-lang="" data-text="MySQL: Get next auto increment value &raquo; innerlogic">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p><a target="_blank" href="http://blog.innerlogic.gr/category/mysql/" title="tag: MySQL"><img border="0" width="474" src="http://blog.innerlogic.gr/wp-content/uploads/2007/05/mysql_logo.png" alt="MySQL" height="183" style="width: 474px; height: 183px" title="MySQL" /></a><br />
Recently, I needed to get the auto increment value for the next inserted row in a MySQL table.  Generally, this is not a good idea and you should stop reading right now.<br />
You may end up with duplicate entries in your application, which is not a good thing.<br />
At a first glance you may think: “I can get the top id value from my table, add 1 and that’s all, I got the next auto_increment value I need.”<br />
Something like this:</p>
<pre lang="php">$query = mysql_query(SELECT MAX(id) as max_id FROM tablename);
$row = mysql_fetch_array($query);
$next_id = $row[‘max_id’] + 1;</pre>
<p>Using the above example, you got the current max auto_increment id plus 1.<br />
As you may already notice, this is wrong. Auto increment values use unique ids.  Imagine the following table:</p>
<pre lang="sql">Id country
1 Italy
2 Germany
3 Greece
4 Turkey</pre>
<p>If you delete the record 4 and run the above script, you will get “4” as next_id.<br />
MySQL will use “5” as next_id.<br />
The solution is to use the “SHOW TABLE STATUS” query.</p>
<pre lang="php">$query = mysql_query(SHOW TABLE STATUS LIKE tablename);
$row = mysql_fetch_array($query);
$next_id = $row[‘Auto_increment’] ;</pre>
<p>The “SHOW TABLE STATUS” command returns a two dimensional array with the “Auto_increment” value among others.</p>
<p><span id="more-36"></span><br />

<!-- Begin Google Adsense code -->
<script type="text/javascript"><!--
google_ad_client = "pub-6089393622205607";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
//2007-06-07: posts
google_ad_channel = "0920911353";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "e87830";
google_color_text = "000000";
google_color_url = "aaaaaa";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<!-- End Google Adsense code -->
</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.innerlogic.gr/mysql-get-next-auto-increment-value/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>MySQL FULLTEXT Stopwords</title>
		<link>http://blog.innerlogic.gr/mysql-fulltext-stopwords/</link>
		<comments>http://blog.innerlogic.gr/mysql-fulltext-stopwords/#comments</comments>
		<pubDate>Thu, 10 May 2007 14:08:50 +0000</pubDate>
		<dc:creator>leo</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://blog.innerlogic.gr/mysql-fulltext-stopwords/</guid>
		<description><![CDATA[Tweet These words could save you a lot of time figuring why this fulltext query returns nothing.. a&#8217;s, able, about, above, according, accordingly, across, actually, after, afterwards, again, against, ain&#8217;t, all, allow, allows, almost, alone, along, already, also, although, always, (&#8230;)</p><p><a href="http://blog.innerlogic.gr/mysql-fulltext-stopwords/">Read the rest of this entry &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: left; margin-bottom: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fblog.innerlogic.gr%2Fmysql-fulltext-stopwords%2F" class="twitter-share-button" data-url="http://blog.innerlogic.gr/mysql-fulltext-stopwords/" data-count="vertical" data-via="" data-lang="" data-text="MySQL FULLTEXT Stopwords &raquo; innerlogic">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p><a href="http://blog.innerlogic.gr/category/mysql/" title="tag: MySQL"><img border="0" width="474" src="http://blog.innerlogic.gr/wp-content/uploads/2007/05/mysql_logo.png" alt="MySQL Logo" height="183" title="MySQL Logo" /></a></p>
<p>These words could save you a lot of time figuring why this fulltext query returns nothing..</p>
<p><em>a&#8217;s, able, about, above, according, accordingly, across, actually, after, afterwards, again, against, ain&#8217;t, all, allow, allows, almost, alone, along, already, also, although, always, am, among, amongst, an, and, another, any, anybody, anyhow, anyone, anything, anyway, anyways, anywhere, apart, appear, appreciate, appropriate, are, aren&#8217;t, around, as, aside, ask, asking, associated, at, available, away, awfully, be, became, because, become, becomes, becoming, been, before, beforehand, behind, being, believe, below, beside, besides, best, better, between, beyond, both, brief, but, by, c&#8217;mon, c&#8217;s, came, can, can&#8217;t, cannot, cant, cause, causes, certain, certainly, changes, clearly, co, com, come, comes, concerning, consequently, consider, considering, contain, containing, contains, corresponding, could, couldn&#8217;t, course, currently, definitely, described, despite, did, didn&#8217;t, different, do, does, doesn&#8217;t, doing, don&#8217;t, done, down, downwards, during, each, edu, eg, eight, either, else, elsewhere, enough, entirely, especially, et, etc, even, ever, every, everybody, everyone, everything, everywhere, ex, exactly, example, except, far, few, fifth, first, five, followed, following, follows, for, former, formerly, forth, four, from, further, furthermore, get, gets, getting, given, gives, go, goes, going, gone, got, gotten, greetings, had, hadn&#8217;t, happens, hardly, has, hasn&#8217;t, have, haven&#8217;t, having, he, he&#8217;s, hello, help, hence, her, here, here&#8217;s, hereafter, hereby, herein, hereupon, hers, herself, hi, him, himself, his, hither, hopefully, how, howbeit, however, i&#8217;d, i&#8217;ll, i&#8217;m, i&#8217;ve, ie, if, ignored, immediate, in, inasmuch, inc, indeed, indicate, indicated, indicates, inner, insofar, instead, into, inward, is, isn&#8217;t, it, it&#8217;d, it&#8217;ll, it&#8217;s, its, itself, just, keep, keeps, kept, know, knows, known, last, lately, later, latter, latterly, least, less, lest, let, let&#8217;s, like, liked, likely, little, look, looking, looks, ltd, mainly, many, may, maybe, me, mean, meanwhile, merely, might, more, moreover, most, mostly, much, must, my, myself, name, namely, nd, near, nearly, necessary, need, needs, neither, never, nevertheless, new, next, nine, no, nobody, non, none, noone, nor, normally, not, nothing, novel, now, nowhere, obviously, of, off, often, oh, ok, okay, old, on, once, one, ones, only, onto, or, other, others, otherwise, ought, our, ours, ourselves, out, outside, over, overall, own, particular, particularly, per, perhaps, placed, please, plus, possible, presumably, probably, provides, que, quite, qv, rather, rd, re, really, reasonably, regarding, regardless, regards, relatively, respectively, right, said, same, saw, say, saying, says, second, secondly, see, seeing, seem, seemed, seeming, seems, seen, self, selves, sensible, sent, serious, seriously, seven, several, shall, she, should, shouldn&#8217;t, since, six, so, some, somebody, somehow, someone, something, sometime, sometimes, somewhat, somewhere, soon, sorry, specified, specify, specifying, still, sub, such, sup, sure, t&#8217;s, take, taken, tell, tends, th, than, thank, thanks, thanx, that, that&#8217;s, thats, the, their, theirs, them, themselves, then, thence, there, there&#8217;s, thereafter, thereby, therefore, therein, theres, thereupon, these, they, they&#8217;d, they&#8217;ll, they&#8217;re, they&#8217;ve, think, third, this, thorough, thoroughly, those, though, three, through, throughout, thru, thus, to, together, too, took, toward, towards, tried, tries, truly, try, trying, twice, two, un, under, unfortunately, unless, unlikely, until, unto, up, upon, us, use, used, useful, uses, using, usually, value, various, very, via, viz, vs, want, wants, was, wasn&#8217;t, way, we, we&#8217;d, we&#8217;ll, we&#8217;re, we&#8217;ve, welcome, well, went, were, weren&#8217;t, what, what&#8217;s, whatever, when, whence, whenever, where, where&#8217;s, whereafter, whereas, whereby, wherein, whereupon, wherever, whether, which, while, whither, who, who&#8217;s, whoever, whole, whom, whose, why, will, willing, wish, with, within, without, won&#8217;t, wonder, would, would, wouldn&#8217;t, yes, yet, you, you&#8217;d, you&#8217;ll, you&#8217;re, you&#8217;ve, your, yours, yourself, yourselves, zero</em></p>
<p><span id="more-35"></span><br />

<!-- Begin Google Adsense code -->
<script type="text/javascript"><!--
google_ad_client = "pub-6089393622205607";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
//2007-06-07: posts
google_ad_channel = "0920911353";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "e87830";
google_color_text = "000000";
google_color_url = "aaaaaa";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<!-- End Google Adsense code -->
</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.innerlogic.gr/mysql-fulltext-stopwords/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

