<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="http://www.bytemycode.com/rssformat.xsl"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>byteMyCode: Snippets for the mercutio</title>
		<link>http://www.bytemycode.com</link>
		<description>Snippets for this member.</description>
		<pubDate>Tue, 02 Dec 2008 00:12:30 +0000</pubDate>
		<copyright>1998-2008 </copyright>
		<language>en-us</language>
		<image>
		      <link>http://www.bytemycode.com</link>
		      <url>http://www.bytemycode.com/img/rss_title.gif</url>
		      <title>byteMyCode</title>
		</image>

	<item>
	<title>SQL Templating</title>
	<link>http://www.bytemycode.com/snippets/snippet/88/</link>
	<comments>http://www.bytemycode.com/snippets/snippet/88/comments/</comments>
	<pubDate>Fri, 17 Feb 2006 04:52:36 +0000</pubDate>
	<dc:creator>mercutio</dc:creator>
	<category>mysql</category>
	<guid isPermaLink="false">http://www.bytemycode.com/snippets/snippet/88/</guid>
	<description>
		<![CDATA[

			<img src="http://www.bytemycode.com/img/icon_calendar.gif" align="middle" class="icon" alt="Date Submitted" /> Fri. Feb. 17th, 2006  4:52 AM			<br />
			<img src="http://www.bytemycode.com/img/icon_revision.gif" align="middle" class="icon" alt="Revision" /> <a href="http://www.bytemycode.com/snippets/snippet/88/revisions/">3</a>
			<br />
			<img src="http://www.bytemycode.com/img/rank_helper.gif" align="middle" class="icon" alt="Helper" /> <a href="http://www.bytemycode.com/members/member/mercutio/" title="Helper">mercutio</a>
			<br />
			<img src="http://www.bytemycode.com/img/icon_tag.gif" align="middle" class="icon" alt="Tags" /> <a href="http://www.bytemycode.com/tags/tag/mysql">mysql</a>			<br />
			<img src="http://www.bytemycode.com/img/icon_comments.gif" align="middle" class="icon" alt="Comments" /> <a href="http://www.bytemycode.com/snippets/snippet/88/comments/">0 comments</a>
			<br />
			<img src="http://www.bytemycode.com/img/icon_ranking.gif" align="middle" class="icon" alt="Ranking" /> -7
			<p>I use this method for keeping my sql templates away from my code.<br /><br />You can extend upon the idea, as I have done in the past, by placing SQL handing classes between your scripts and the template library.<br /><br />Things to note here:<br /><br />The lesser userd heredoc string method. The reason this is used is to keep the SQL clear and well laid out, and not as messy as using quotes.<br /><br />vsprintf() is a very handy function if you don't want to hard code the number of parameters to interpolate your string with.<br /><br />The use of sprintf templates offers you additional security. For example, only allowing numbers to be placed where a %d falls. This, of course, shouldn't be the only security on user supplied variables, but comes in extra handy for debugging purposes.<br /><br />Regarding the TODO in there, it would take a check of the number of % placeholders there are in the template. One caveat is remembering to remove the count of %%'s that appear (the literal percentage).</p>
		]]>
	</description>
</item>
	</channel>
</rss>