<?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>Leading Edge Scripts &#187; Databases</title>
	<atom:link href="http://leadingedgescripts.co.uk/category/databases/feed/" rel="self" type="application/rss+xml" />
	<link>http://leadingedgescripts.co.uk</link>
	<description></description>
	<lastBuildDate>Fri, 16 Oct 2009 09:14:32 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Preventing SQL Injection</title>
		<link>http://leadingedgescripts.co.uk/web-development/preventing-sql-injection/</link>
		<comments>http://leadingedgescripts.co.uk/web-development/preventing-sql-injection/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 16:43:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Computer Security]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[clean up input data]]></category>
		<category><![CDATA[sql injection]]></category>

		<guid isPermaLink="false">http://www.leadingedgescripts.co.uk/?p=222</guid>
		<description><![CDATA[For anyone who needs it, here is a script I wrote to prevent SQL injection. It uses references to the original global arrays to clean them up.



&#160;


/**


&#160;* added the following code to enabled readyness for magic_quotes() being removed


&#160;* in PHP6


&#160;* 


&#160;* added by C. Cook 15/8/2008 


&#160;*/


//Turn off magic quotes the manual way, this also [...]]]></description>
			<content:encoded><![CDATA[<p>For anyone who needs it, here is a script I wrote to prevent SQL injection. It uses references to the original global arrays to clean them up.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* added the following code to enabled readyness for magic_quotes() being removed</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* in PHP6</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp;* </span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* added by C. Cook 15/8/2008 </span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//Turn off magic quotes the manual way, this also cleans up all our nasty data&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span></div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$in</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span>&amp;<span class="re0">$_GET</span>, &amp;<span class="re0">$_POST</span>, &amp;<span class="re0">$_COOKIE</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">while</span> <span class="br0">&#40;</span><a href="http://www.php.net/list"><span class="kw3">list</span></a><span class="br0">&#40;</span><span class="re0">$k</span>, <span class="re0">$v</span><span class="br0">&#41;</span> = <a href="http://www.php.net/each"><span class="kw3">each</span></a><span class="br0">&#40;</span><span class="re0">$in</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$v</span> <span class="kw1">as</span> <span class="re0">$key</span> =&gt; <span class="re0">$val</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/is_array"><span class="kw3">is_array</span></a><span class="br0">&#40;</span><span class="re0">$val</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//now we re-escape our input data</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$in</span><span class="br0">&#91;</span><span class="re0">$k</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="re0">$key</span><span class="br0">&#93;</span> = <a href="http://www.php.net/mysql_real_escape_string"><span class="kw3">mysql_real_escape_string</span></a><span class="br0">&#40;</span><a href="http://www.php.net/stripslashes"><span class="kw3">stripslashes</span></a><span class="br0">&#40;</span><span class="re0">$val</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//$in[$k][$key] = stripslashes($val);&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">continue</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$in</span><span class="br0">&#91;</span><span class="br0">&#93;</span> =&amp; <span class="re0">$in</span><span class="br0">&#91;</span><span class="re0">$k</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="re0">$key</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><a href="http://www.php.net/unset"><span class="kw3">unset</span></a><span class="br0">&#40;</span><span class="re0">$in</span><span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://leadingedgescripts.co.uk/web-development/preventing-sql-injection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Database development &#8211; Some Rules</title>
		<link>http://leadingedgescripts.co.uk/web-development/database-development-some-rules/</link>
		<comments>http://leadingedgescripts.co.uk/web-development/database-development-some-rules/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 21:56:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[phpmyadmin]]></category>

		<guid isPermaLink="false">http://www.leadingedgescripts.co.uk/?p=173</guid>
		<description><![CDATA[







If I&#8217;d known this stuff when I first started to design databases for web applications, I think it would have helped me a lot, these are not necessarily &#8216;formal recommendations&#8217; or even what some people might call &#8216;best practice&#8217;, but these rules work for me when I&#8217;m designing my web applications. It makes development quicker, [...]]]></description>
			<content:encoded><![CDATA[<p>
<!-- Begin Google Adsense code -->
<script type="text/javascript"><!--
google_ad_client = "pub-4904188713812219";
/* 468x60, created 02/11/08 */
google_ad_slot = "9286450703";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<!-- End Google Adsense code -->
</p>
<p>If I&#8217;d known this stuff when I first started to design databases for web applications, I think it would have helped me a lot, these are not necessarily &#8216;formal recommendations&#8217; or even what some people might call &#8216;best practice&#8217;, but these rules work for me when I&#8217;m designing my web applications. It makes development quicker, because I don&#8217;t have to think about the names of my columns and tables when I&#8217;m writing code.</p>
<p>So with that in mind, these are my &#8216;rules&#8217; for database design:</p>
<ol>
<li>Name everything in lowercase, that means table names, column names, everything!</li>
<li>always use the plural for table names</li>
<li>always use singular for columns names</li>
<li>always name primary key &#8216;index&#8217; fields &#8216;id&#8217; this prevents any issues with the name &#8216;index&#8217;</li>
<li>always name your database columns using something that accurately describes the content of the column e.g. email, first_name, last_name, tel</li>
</ol>
<p>Short and sweet, but these rules stand me in good stead these days.</p>
<p>On a similar topic, and equally useful, use a database administration tool, like <a href="http://dev.mysql.com/downloads/gui-tools/5.0.html">MySQLAdministrator</a> since it&#8217;s so much faster than installing old faithful <a href="http://www.phpmyadmin.net/home_page/index.php">PhpMyAdmin</a>. Don&#8217;t get me wrong PhpMyAdmin is still great, and I still use it a lot, but when I can get away with it MySQLAdministrator is just so much faster for creating databases tables.</p>
]]></content:encoded>
			<wfw:commentRss>http://leadingedgescripts.co.uk/web-development/database-development-some-rules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to backup and email a dump of your Mysql database on Linux</title>
		<link>http://leadingedgescripts.co.uk/web-development/how-to-backup-and-email-a-dump-of-your-mysql-database-on-linux/</link>
		<comments>http://leadingedgescripts.co.uk/web-development/how-to-backup-and-email-a-dump-of-your-mysql-database-on-linux/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 17:55:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Computer Security]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.leadingedgescripts.co.uk/wp/?p=24</guid>
		<description><![CDATA[A few weeks back, after working on an old, slow &#38; clunking server that I use to run a billing system, I thought to myself ‘hey you know what, it would be great to be able to email myself backups of my MySQL database. That will stop me worrying about loosing all this data if [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks back, after working on an old, slow &amp; clunking server that I use to run a billing system, I thought to myself ‘hey you know what, it would be great to be able to email myself backups of my MySQL database. That will stop me worrying about loosing all this data if this server ever dies on me.’</p>
<p>So, as you’ve probably guessed, I figured out how to do it. The answer’s actually very simple, and can easily be run as a cron job to automate the process on a daily basis.</p>
<p>
<!-- Begin Google Adsense code -->
<script type="text/javascript"><!--
google_ad_client = "pub-4904188713812219";
/* 468x60, created 02/11/08 */
google_ad_slot = "9286450703";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<!-- End Google Adsense code -->
</p>
<p>First you need to make your MySQL dump file. (I prefer .sql files as I think it makes things way more transferable)</p>
<p>The command to dump all your data from MySQL is this:</p>
<p>          mysqldump –u username –p databasename &gt; mysqldumpfilename.sql</p>
<p>This will output a copy of your entire database to the file called mysqldumpfilename.sql (of course you can call yours whatever you want)</p>
<p>The next step is to get this file emailed to you. Somewhere (I don’t remember where) I found out that you should encode your mail attachments using the uuencode function in Linux.</p>
<p>So to email yourself a copy of your database backup, the command is as follows:</p>
<p>          uuencode mysqldumpfilename.sql mysqldumpfilename.sql | mail sylvia@home.com</p>
<p>Now just put the two together and you can email yourself a backup of your mysql database.</p>
]]></content:encoded>
			<wfw:commentRss>http://leadingedgescripts.co.uk/web-development/how-to-backup-and-email-a-dump-of-your-mysql-database-on-linux/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
