<?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>Brain Goo &#187; SQL</title>
	<atom:link href="http://www.popmartian.com/tipsntricks/category/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.popmartian.com/tipsntricks</link>
	<description>Carpe Crap 'em</description>
	<lastBuildDate>Mon, 10 Oct 2011 14:42:08 +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>SQL: Select duplicate rows, select indistinct rows</title>
		<link>http://www.popmartian.com/tipsntricks/2008/10/27/sql-select-duplicate-rows-select-indistinct-rows/</link>
		<comments>http://www.popmartian.com/tipsntricks/2008/10/27/sql-select-duplicate-rows-select-indistinct-rows/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 16:09:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[How Tos]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://www.popmartian.com/tipsntricks/?p=67</guid>
		<description><![CDATA[Using SQL, MySQL or whatever your favorite database may be, we all know using SELECT DISTINCT will return unique values in case a value appears more than once in a table. How do you fine duplicates? What if I want to know where the duplicates are? The trick is to use count() and compare it [...]]]></description>
			<content:encoded><![CDATA[<p>Using SQL, MySQL or whatever your favorite database may be, we all know using <code>SELECT DISTINCT</code> will return unique values in case a value appears more than once in a table.</p>
<p>How do you fine duplicates?  What if I want to know where the duplicates are?</p>
<p>The trick is to use count() and compare it to an integer.</p>
<p><code>SELECT count(*), locations.* FROM locations GROUP BY number HAVING COUNT(*) > 1</code></p>
<p>That will select a count of unique instances of a value from a table called &#8220;locations&#8221;, group them by a field called &#8220;number&#8221; where the count is greater than 1.  In other words, it will return all the fields where there are more than one instance of the same value in the column &#8220;number&#8221;.</p>
<blockquote><p>Did you find this post useful or have questions or comments?  Please let me know!</p></blockquote>
<img src="http://www.popmartian.com/tipsntricks/?ak_action=api_record_view&id=67&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.popmartian.com/tipsntricks/2008/10/27/sql-select-duplicate-rows-select-indistinct-rows/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Quick Character Escaping in PHP</title>
		<link>http://www.popmartian.com/tipsntricks/2007/10/10/quick-character-escaping-in-php/</link>
		<comments>http://www.popmartian.com/tipsntricks/2007/10/10/quick-character-escaping-in-php/#comments</comments>
		<pubDate>Wed, 10 Oct 2007 17:48:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.popmartian.com/tipsntricks/2007/10/10/quick-character-escaping-in-php/</guid>
		<description><![CDATA[When writing PHP web apps, I tend to run in to a portability issue when dealing with SQL connectivity. Since I can&#8217;t count on having the PEAR DB module available, I rolled my own set of functions to interact with a MySQL database. The problem lies in escaping characters in your SQL queries. Do I [...]]]></description>
			<content:encoded><![CDATA[<p>When writing PHP web apps, I tend to run in to a portability issue when dealing with SQL connectivity.  Since I can&#8217;t count on having the PEAR DB module available, I rolled my own set of functions to interact with a MySQL database.</p>
<p>The problem lies in escaping characters in your SQL queries.  Do I <code>addslashes()</code>?  Is magic_quotes_gpc enabled?</p>
<p>My quick-and-dirty solution is the following function:</p>
<p><code><br />
function request_cleanup()<br />
{<br />
&nbsp;&nbsp;if(get_magic_quotes_gpc() == 0)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;foreach($_REQUEST as $req_key => $req_value)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$_REQUEST[$req_key]=addslashes($_REQUEST[$req_key]);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
}<br />
</code></p>
<p>By calling that function on every page that deals with inserting content in to the database, I know will will get my content escaped correctly.</p>
<p>Of course it escapes all submitted content, including that which isn&#8217;t going in to the database so don&#8217;t forget to <code>stripslashes()</code> when you are working with data that doesn&#8217;t need it.</p>
<p>Example:<br />
<code><br />
request_cleanup();</p>
<p>$notes = $_REQUEST['notes '];<br />
$confirmation = stripslashes($_REQUEST['notes ']);</p>
<p>$SQL = "INSERT INTO notes (note) VALUES ('$notes')";<br />
sql_proc($SQL);</p>
<p>print "Your note was: $confirmation";<br />
</code></p>
<img src="http://www.popmartian.com/tipsntricks/?ak_action=api_record_view&id=18&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.popmartian.com/tipsntricks/2007/10/10/quick-character-escaping-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

