<?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>#Adam.Blog# &#187; code</title>
	<atom:link href="http://blog.adampresley.com/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.adampresley.com</link>
	<description>I&#039;m bringin&#039; nerdy back.</description>
	<lastBuildDate>Fri, 03 Sep 2010 15:59:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/><atom:link rel="hub" href="http://github.com/tonyg/rabbithub"/>		<item>
		<title>Parsing PHP-style Placeholders for SQL Scripts</title>
		<link>http://blog.adampresley.com/2008/parsing-php-style-placeholders-for-sql-scripts/</link>
		<comments>http://blog.adampresley.com/2008/parsing-php-style-placeholders-for-sql-scripts/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 05:12:49 +0000</pubDate>
		<dc:creator>Adam Presley</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.adampresley.com/?p=276</guid>
		<description><![CDATA[If you&#8217;ve ever used PHP, you&#8217;ve probably used, or at least seen, the PRINTF and/or SPRINTF functions. These oldie, but goodie, functions are stolen&#8230; err&#8230; borrowed from the old C language world. Both functions support the abililty to have placeholders, which when evaluated, are replaced with the value in a comma-delimited list in the appropriate [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever used PHP, you&#8217;ve probably used, or at least seen, the <a href="http://us2.php.net/manual/en/function.printf.php" target="_blank"><em>PRINTF</em></a> and/or <a href="http://us2.php.net/manual/en/function.sprintf.php" target="_blank"><em>SPRINTF</em></a> functions. These oldie, but goodie, functions are stolen&#8230; err&#8230; borrowed from the old <a href="http://en.wikipedia.org/wiki/C_language" target="_blank">C language</a> world. Both functions support the abililty to have placeholders, which when evaluated, are replaced with the value in a comma-delimited list in the appropriate position. For example:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;My name is <span style="color: #009933; font-weight: bold;">%s</span>. I am %i years old&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$age</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>This code, given that <strong>$name</strong> equals &#8220;Adam&#8221;, and <strong>$age</strong> equals &#8220;30&#8243; will output &#8220;My name is Adam. I am 30 years old&#8221;. A nifty feature.</p>

<p>Below is a bit of code that provides a class that will take a given input SQL string, an array of arguments, and spit out a parsed SQL string. An example of usage would look like so:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$userId</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$parser</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SqlScriptParser<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT name, email, active FROM users WHERE userId=%i&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$userId</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$parser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Parse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>The resulting string would look like:</p>

<p><strong>SELECT name, email, active FROM users WHERE userId=30</strong></p>

<p>The code: <a href="http://www.adampresley.com/downloads/code/php/sqlScriptParser.zip">http://www.adampresley.com/downloads/code/php/sqlScriptParser.zip</a></p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.adampresley.com/2008/parsing-php-style-placeholders-for-sql-scripts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
