<?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>Saiweb &#187; sql</title>
	<atom:link href="http://www.saiweb.co.uk/tag/sql/feed" rel="self" type="application/rss+xml" />
	<link>http://www.saiweb.co.uk</link>
	<description>Ramblings of a Sys admin</description>
	<lastBuildDate>Mon, 06 Feb 2012 14:57:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>mySQL &gt;= 5.0.37 community profiling SQL queries.</title>
		<link>http://www.saiweb.co.uk/mysql/mysql-5-0-37-community-profiling-sql-queries</link>
		<comments>http://www.saiweb.co.uk/mysql/mysql-5-0-37-community-profiling-sql-queries#comments</comments>
		<pubDate>Thu, 15 Jul 2010 19:30:06 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[mySQL]]></category>
		<category><![CDATA[5.0.37]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[profiling]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[slow]]></category>
		<category><![CDATA[slow query]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/?p=885</guid>
		<description><![CDATA[Whilst there indeed seems to be a veritable plethora of SQL profiling / benchmarking tools, most of them with insane commercial license fees (&#62;= $400 per annum on most) I have found it intriguing that as of mySQL community edition &#62;= 5.0.37 mySQL offers an inbuilt method for profiling SQL queries, as can be see [...]]]></description>
			<content:encoded><![CDATA[<p>Whilst there indeed seems to be a veritable plethora of SQL profiling / benchmarking tools, most of them with insane commercial license fees (&gt;= $400 per annum on most)</p>
<p>I have found it intriguing that as of mySQL community edition &gt;= 5.0.37 mySQL offers an inbuilt method for profiling SQL queries, as can be see <a href="http://dev.mysql.com/doc/refman/5.0/en/show-profiles.html">here</a> the downside is that this is session based, meaning it can only provide profiling information for the current connection, almost useless for trying to profile a running web app (that is without code modification to set profiling and harvest the data).</p>
<p>However it can be useful if you have a known slow query.</p>
<p>So lets work on the basis that we have a known slow SQL query we&#8217;d like profiling information for,</p>
<p>check to see if profiling is enabled:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> &nbsp;@@profiling;</div></td></tr></tbody></table></div>
<p>The returned value is generally 0 so lets enable it.</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SET</span> profiling_history_size<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">100</span>;<br />
<span style="color: #993333; font-weight: bold;">SET</span> profiling<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span>;</div></td></tr></tbody></table></div>
<p>This tells mySQL to retain the profile of 100 queries in memory, and to enable profiling.</p>
<p>Now at this point this can also be used to diagnose slow loading datases, simply</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">USE</span> <span style="color: #66cc66;">&lt;</span>dbname<span style="color: #66cc66;">&gt;</span>;<br />
<span style="color: #993333; font-weight: bold;">SHOW</span> profiles;<br />
<span style="color: #993333; font-weight: bold;">SHOW</span> profile <span style="color: #993333; font-weight: bold;">FOR</span> <span style="color: #cc66cc;">1</span>;</div></td></tr></tbody></table></div>
<p>Upon running the above you will now be using your database and will see an output similar to</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">+----------+------------+-------------------+<br />
| Query_ID | Duration &nbsp; | Query &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |<br />
+----------+------------+-------------------+<br />
| &nbsp; &nbsp; &nbsp; &nbsp;1 | 0.00011400 | SELECT DATABASE() |<br />
| &nbsp; &nbsp; &nbsp; &nbsp;2 | 0.00048900 | show databases &nbsp; &nbsp;|<br />
| &nbsp; &nbsp; &nbsp; &nbsp;3 | 0.00026600 | show tables &nbsp; &nbsp; &nbsp; |<br />
+----------+------------+-------------------+</div></td></tr></tbody></table></div>
<p>Followed by</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">+----------------------+----------+<br />
| Status &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Duration |<br />
+----------------------+----------+<br />
| starting &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 0.000053 |<br />
| checking permissions | 0.000004 |<br />
| Opening tables &nbsp; &nbsp; &nbsp; | 0.000009 |<br />
| init &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 0.000011 |<br />
| optimizing &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 0.000004 |<br />
| executing &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000017 |<br />
| end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000003 |<br />
| end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000002 |<br />
| query end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000002 |<br />
| freeing items &nbsp; &nbsp; &nbsp; &nbsp;| 0.000005 |<br />
| logging slow query &nbsp; | 0.000002 |<br />
| cleaning up &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000002 |<br />
+----------------------+----------+</div></td></tr></tbody></table></div>
<p>In my case here nothing really eventful, lets assume for the moment you are using a wordpress database, and you have numerous posts</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> wp_posts <span style="color: #993333; font-weight: bold;">WHERE</span> ID <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">100</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span>ID<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> wp_posts <span style="color: #993333; font-weight: bold;">WHERE</span> ID <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">100</span></div></td></tr></tbody></table></div>
<p>in my case I got the following results:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">0.00072600 | select count(*) from wp_posts where ID &amp;gt; 100<br />
0.00069900 | select count(ID) from wp_posts where ID &amp;gt; 100</div></td></tr></tbody></table></div>
<p>a simple demonstration showing the difference between a count() on an indexed field vs *, in this case the saving is ~4%.</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SHOW</span> profiles;<br />
<span style="color: #993333; font-weight: bold;">SHOW</span> profile <span style="color: #993333; font-weight: bold;">FOR</span> query <span style="color: #66cc66;">&lt;</span>n<span style="color: #66cc66;">&gt;</span>;</div></td></tr></tbody></table></div>
<p>Will give you an output similar to:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">+--------------------+----------+<br />
| Status &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Duration |<br />
+--------------------+----------+<br />
| starting &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 0.000079 |<br />
| Opening tables &nbsp; &nbsp; | 0.000014 |<br />
| System lock &nbsp; &nbsp; &nbsp; &nbsp;| 0.000005 |<br />
| Table lock &nbsp; &nbsp; &nbsp; &nbsp; | 0.000008 |<br />
| init &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 0.000025 |<br />
| optimizing &nbsp; &nbsp; &nbsp; &nbsp; | 0.000012 |<br />
| statistics &nbsp; &nbsp; &nbsp; &nbsp; | 0.000049 |<br />
| preparing &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000012 |<br />
| executing &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000006 |<br />
| Sending data &nbsp; &nbsp; &nbsp; | 0.000461 |<br />
| end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000004 |<br />
| end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000003 |<br />
| query end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000003 |<br />
| freeing items &nbsp; &nbsp; &nbsp;| 0.000007 |<br />
| closing tables &nbsp; &nbsp; | 0.000005 |<br />
| logging slow query | 0.000003 |<br />
| cleaning up &nbsp; &nbsp; &nbsp; &nbsp;| 0.000003 |<br />
+--------------------+----------+<br />
17 rows in set (0.00 sec)</div></td></tr></tbody></table></div>
<p>this is very similar to a <a href="http://en.wikipedia.org/wiki/Strace">stack trace</a> you may run on a problematic script, or <a href="http://www.xdebug.org">xdebug</a> + <a href="http://code.google.com/p/webgrind/">webgrind</a>, and will gain futher insight into your SQL should <a href="http://dev.mysql.com/doc/refman/5.0/en/explain.html">EXPLAIN</a> no give you enough of an insight.</p>
<p>I&#8217;ll post more information on this as I get time to work with it more, this is still knew to me, and aside from knowing how to use it I know relatively little about this profiling functionality, please feel free to post references / examples in the comments.</p>
<p>Cheers</p>
<p>Buzz<span style="float: left;" ><a class="twitter-share-button"  data-via="Saiweb" data-count="horizontal" data-related="Saiweb:David Busby" data-lang="en" data-url="http://www.saiweb.co.uk/mysql/mysql-5-0-37-community-profiling-sql-queries" data-text="mySQL >= 5.0.37 community profiling SQL queries.&#8221; href=&#8221;http://twitter.com/share?via=Saiweb&#038;count=horizontal&#038;related=Saiweb%3ADavid%20Busby&#038;lang=en&#038;url=http%3A%2F%2Fwww.saiweb.co.uk%2Fmysql%2Fmysql-5-0-37-community-profiling-sql-queries&#038;text=mySQL%20%3E%3D%205.0.37%20community%20profiling%20SQL%20queries.&#8221; >Tweet</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/mysql/mysql-5-0-37-community-profiling-sql-queries/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Security considerations, a quick reference for the newbies.</title>
		<link>http://www.saiweb.co.uk/security/php-security-considerations</link>
		<comments>http://www.saiweb.co.uk/security/php-security-considerations#comments</comments>
		<pubDate>Thu, 20 Mar 2008 09:57:17 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[mySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[injection]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/php/php-security-considerations</guid>
		<description><![CDATA[To often I get passed code to review that quite frankly is so full of holes it wouldn&#8217;t make an adequate sieve&#8230; So in this quick blog I outline a few simple and easily implemented steps to ensure as you start out in the world of PHP, your first site isn&#8217;t hacked within 5 minutes, [...]]]></description>
			<content:encoded><![CDATA[<p>To often I get passed code to review that quite frankly is so full of holes it wouldn&#8217;t make an adequate sieve&#8230;</p>
<p>So in this quick blog I outline a few simple and easily implemented steps to ensure as you start out in the world of PHP, your first site isn&#8217;t hacked within 5 minutes, leaving you a whimpering wrek &#8230;</p>
<p><strong>PHP DON&#8217;T EXAMPLE 1:</strong></p>
<p>Passing RAW globals to mysql!</p>
<p>i.e.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$sql = &quot;SELECT * FROM users WHERE email='.$_GET['email'].&quot;' and password='&quot;.$_GET['password']&quot;';&quot;;<br />
$result = mysql_query($sql);</div></td></tr></tbody></table></div>
<p>So what is wrong with the above? <strong><a title="SQL INject Wikipedia Entry" href="http://en.wikipedia.org/wiki/SQL_injection" target="_blank">SQL INJECTION</a> </strong>welcome to a world where people want to break your website, simply because they can &#8230;</p>
<p>I am not going to add more description, just click through to the wiki pedia entry linked above &#8230;</p>
<p>To avoid this PHP comes with two functions <a title="PHP mysql_escape_string()" href="http://www.php.net/mysql_escape_string" target="_blank">mysql_escape_string()</a> and <a title="PHP mysql_real_escape_string()" href="http://www.php.net/mysql_real_escape_string" target="_blank">mysql_real_escape_string()</a></p>
<p>An example taken from the <a title="PHP mysql_real_escape_string()" href="http://www.php.net/mysql_real_escape_string" target="_blank">mysql_real_escape_string()</a> page:</p>
<p class="example"><strong>Example#2 An example SQL Injection Attack</strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;span style=&quot;color: #000000;&quot;&gt;&lt;span style=&quot;color: #0000bb;&quot;&gt;&amp;lt;?php<br />
&lt;/span&gt;&lt;span style=&quot;color: #ff8000;&quot;&gt;// Query database to check if there are any matching users<br />
&lt;/span&gt;&lt;span style=&quot;color: #0000bb;&quot;&gt;$query &lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #dd0000;&quot;&gt;&quot;SELECT * FROM users WHERE user='{$_POST['username']}' AND password='{$_POST['password']}'&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;;<br />
&lt;/span&gt;&lt;span style=&quot;color: #0000bb;&quot;&gt;mysql_query&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000bb;&quot;&gt;$query&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;</div></td></tr></tbody></table></div>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;span style=&quot;color: #000000;&quot;&gt;&lt;span style=&quot;color: #007700;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff8000;&quot;&gt;// We didn't check $_POST['password'], it could be anything the user wanted! For example:<br />
&lt;/span&gt;&lt;span style=&quot;color: #0000bb;&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #dd0000;&quot;&gt;'username'&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;] = &lt;/span&gt;&lt;span style=&quot;color: #dd0000;&quot;&gt;'aidan'&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;;<br />
&lt;/span&gt;&lt;span style=&quot;color: #0000bb;&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #dd0000;&quot;&gt;'password'&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;] = &lt;/span&gt;&lt;span style=&quot;color: #dd0000;&quot;&gt;&quot;' OR ''='&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&lt;span style=&quot;color: #ff8000;&quot;&gt;// This means the query sent to MySQL would be:<br />
&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;echo &lt;/span&gt;&lt;span style=&quot;color: #0000bb;&quot;&gt;$query&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;;<br />
&lt;/span&gt;&lt;span style=&quot;color: #0000bb;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;</div></td></tr></tbody></table></div>
<p class="example-contents">The query sent to MySQL:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;code&gt;SELECT * FROM users WHERE user='aidan' AND password='' OR ''=''</div></td></tr></tbody></table></div>
<p></code></p>
<p class="example-contents">This would allow anyone to log in without a valid password.</p>
<p class="example-contents">So in summary READ the <a title="PHP mysql_real_escape_string()" href="http://www.php.net/mysql_real_escape_string" target="_blank">mysql_real_escape_string()</a> page, and even if you don't implement the "best practice" example on that page PLEASE make sure you at least escape $_SESSION $_GET $_POST inputs with a mysql escape function!</p>
<p class="example-contents">
<p class="example-contents">
<p><span style="float: left;" ><a class="twitter-share-button"  data-via="Saiweb" data-count="horizontal" data-related="Saiweb:David Busby" data-lang="en" data-url="http://www.saiweb.co.uk/security/php-security-considerations" data-text="PHP Security considerations, a quick reference for the newbies." href="http://twitter.com/share?via=Saiweb&#038;count=horizontal&#038;related=Saiweb%3ADavid%20Busby&#038;lang=en&#038;url=http%3A%2F%2Fwww.saiweb.co.uk%2Fsecurity%2Fphp-security-considerations&#038;text=PHP%20Security%20considerations%2C%20a%20quick%20reference%20for%20the%20newbies." >Tweet</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/security/php-security-considerations/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using apc
Database Caching 5/21 queries in 0.043 seconds using apc
Object Caching 1033/1075 objects using apc
Content Delivery Network via Rackspace Cloud Files: cdn.saiweb.co.uk

Served from: www.saiweb.co.uk @ 2012-02-07 16:28:53 -->
