<?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>Jordan Hall &#187; MySQL</title>
	<atom:link href="http://jordanhall.co.uk/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://jordanhall.co.uk</link>
	<description>Jordan Hall - programmer and geek</description>
	<lastBuildDate>Thu, 19 Jan 2012 11:36:06 +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>Storing PHP Session data in a database</title>
		<link>http://jordanhall.co.uk/programming/storing-php-session-data-in-a-database-20061251/</link>
		<comments>http://jordanhall.co.uk/programming/storing-php-session-data-in-a-database-20061251/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 12:32:20 +0000</pubDate>
		<dc:creator>Jordan Hall</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[database PHP sessions]]></category>
		<category><![CDATA[database storage]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL server]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP session]]></category>
		<category><![CDATA[PHP session storage]]></category>
		<category><![CDATA[PHP sessions]]></category>
		<category><![CDATA[PHP sessions in MySQL database]]></category>

		<guid isPermaLink="false">http://jordanhall.co.uk/?p=1251</guid>
		<description><![CDATA[I&#8217;ve recently exchanged e-mails with a colleague regarding the storage of PHP sessions data in a MySQL database. To help anyone else interested in using database storage of PHP session information, I have paraphrased / rewritten the content of some of those e-mails below. One of the best ways to implement the database storage of PHP session [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jordanhall.co.uk/wp-content/uploads/2011/06/php-and-mysql-logos.gif"><img class="alignright size-thumbnail wp-image-1276" title="PHP and MySQL logos" src="http://jordanhall.co.uk/wp-content/uploads/2011/06/php-and-mysql-logos-150x150.gif" alt="PHP and MySQL logos" width="150" height="150" /></a>I&#8217;ve recently exchanged e-mails with a colleague regarding the storage of PHP sessions data in a MySQL database. To help anyone else interested in using database storage of PHP session information, I have paraphrased / rewritten the content of some of those e-mails below.</p>
<p>One of the best ways to implement the database storage of PHP session data is via the overriding session handlers built in to PHP. PHP has functions built in to allow you to override the default file based session handlers.</p>
<p>These functions all use PHP&#8217;s normal ways of handling session persistence between the client and the server (by default, via the use of a session ID cookie).</p>
<p>In other words, it utilises the same PHPSESSID cookie that the default file based session storage uses. When using functions that override the session handlers, the first parameter for several of these function is the session id. Upon overriding the functions, PHP will automatically pass the session ID (pulled from the PHPSESSID cookie) to these functions.</p>
<p>The code linked to below can be &#8216;required&#8217; (require &#8220;session_start.php&#8221;) as a drop in replacement for the default PHP session_start() function. This utilises database access to store and retrieve session information. Note that due to the very early point in which PHP processes session handler overrides, objects are not available for use, hence the use of old style &#8216;mysql&#8217; instead of OO based &#8216;mysqli&#8217; (if you find a way around this, I&#8217;d be very interested in hearing about it).</p>
<p style="text-align: center;"><strong><a title="Session Start PHP code" href="http://jordanhall.co.uk/content/sessionstart.txt" target="_blank">Download &#8216;session_start.php&#8217; for database storage of session data</a></strong></p>
<p style="text-align: center;"><strong><a title="SQL Database Table Structure" href="http://jordanhall.co.uk/content/sessionstart_requiredsql.txt" target="_blank">Required Table Structure SQL</a></strong></p>
<p>In terms of performance, there is limited degradation to using database stored sessions with most small to mid range sites, based on my experience and observation. However, larger sites may possiblynotice degradation. In such circumstances, this would likely be related to the MySQL database server load and/or high levels of IO on the MySQL server. Issues of database server load can be mitigated via one or more of the following:</p>
<ul>
<li>Separation of the site database and the session storage database (seperating each to their own server if necessary)</li>
<li>File based caching of session information on the web server system (using standard PHP file reading/writing functions, ensuring that the file cache is updated whenever there are changes to the session information in the database store)</li>
<li>In memory caching (similar to file based caching, but utilising a key to value storage engine which runs in RAM, providing very fast (atomic) access to data) &#8211; using a system such as memcached - <a href="http://memcached.org/" target="_blank">http://memcached.org/</a></li>
</ul>
<p>For building reasonable size websites in which portability is important, the need to load balance is highly probably in the future and where development time permits, I&#8217;d  personal recommend database storage for session information, due to the higher level of flexibility this set-up offers.</p>
<p>I hope this information helps anyone looking to make a PHP powered site just that little bit more portable by placing their users&#8217; session data in a database.</p>
]]></content:encoded>
			<wfw:commentRss>http://jordanhall.co.uk/programming/storing-php-session-data-in-a-database-20061251/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SQL Check Constraints not supported in MySQL</title>
		<link>http://jordanhall.co.uk/general-articles/sql-check-constraints-not-supported-in-mysql-2204849/</link>
		<comments>http://jordanhall.co.uk/general-articles/sql-check-constraints-not-supported-in-mysql-2204849/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 16:12:22 +0000</pubDate>
		<dc:creator>Jordan Hall</dc:creator>
				<category><![CDATA[General Articles]]></category>
		<category><![CDATA[check constraints]]></category>
		<category><![CDATA[constraints]]></category>
		<category><![CDATA[database schema]]></category>
		<category><![CDATA[database validation]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://jordanhall.co.uk/?p=849</guid>
		<description><![CDATA[I previously wrote about using SQL check constraints in MySQL. It seems however that the MySQL relational database management system (RDBMS) does not actually support the fundamental verification used by check constraints in other RDBMSs. This means that although you can add check constraints to tables without issue, they are not validated and data is [...]]]></description>
			<content:encoded><![CDATA[<p>I previously wrote about using <a href="http://jordanhall.co.uk/general-articles/sql-check-constraints-on-mysql-databases-2102526/">SQL check constraints in MySQL</a>. It seems however that the MySQL relational database management system (RDBMS) does not actually support the fundamental verification used by check constraints in other RDBMSs. This means that although you can add check constraints to tables without issue, they are not validated and data is inserted or updated.</p>
<p>The latest <a href="http://dev.mysql.com/doc/refman/5.5/en/table-constraints-table.html">MySQL documentation</a> (5.5) discretly mentions the fact these constraints are unfortunately not supported.</p>
<blockquote>
<ul>
<li>The CONSTRAINT_TYPE value can be UNIQUE, PRIMARY KEY, or FOREIGN KEY.</li>
<li>The UNIQUE and PRIMARY KEY information is about the same as what you get from the Key_name field in the output from SHOW INDEX when the Non_unique field is 0.</li>
<li>The CONSTRAINT_TYPE column can contain one of these values: UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK. This is a CHAR (not ENUM) column. <strong>The CHECK value is not available until we support CHECK.</strong></li>
</ul>
</blockquote>
<p>Take special note of the final line I&#8217;ve emboldened. This is quite a shame that this constraint type is not fully supported yet.</p>
<p>Apologies to readers for the implication that this was functional in my previous post, and thanks to the poster of <a href="http://jordanhall.co.uk/general-articles/sql-check-constraints-on-mysql-databases-2102526/comment-page-1/#comment-1370">this comment</a> for noticing the discrepancy.</p>
<p>Check constraints, of course, function fine in many other DBMSs, and to that end, the original post on <a href="http://jordanhall.co.uk/general-articles/sql-check-constraints-on-mysql-databases-2102526/">SQL check constraints</a> is still relevant, but sadly not if you are worked with MySQL.</p>
]]></content:encoded>
			<wfw:commentRss>http://jordanhall.co.uk/general-articles/sql-check-constraints-not-supported-in-mysql-2204849/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>SQL Check Constraints on MySQL Databases</title>
		<link>http://jordanhall.co.uk/general-articles/sql-check-constraints-on-mysql-databases-2102526/</link>
		<comments>http://jordanhall.co.uk/general-articles/sql-check-constraints-on-mysql-databases-2102526/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 13:25:21 +0000</pubDate>
		<dc:creator>Jordan Hall</dc:creator>
				<category><![CDATA[General Articles]]></category>
		<category><![CDATA[check constraints]]></category>
		<category><![CDATA[database schema]]></category>
		<category><![CDATA[database validation]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Check Constraints]]></category>

		<guid isPermaLink="false">http://jordanhall.co.uk/?p=526</guid>
		<description><![CDATA[An SQL check constraint is used and designed in the schema of a database table to restrict the range of values that can be entered into a specific field. In many experienced, they are very rarely used. However, these simple checks, entered at the time of database table creation, can provide additional safe guards against [...]]]></description>
			<content:encoded><![CDATA[<p>An SQL check constraint is used and designed in the schema of a database table to restrict the range of values that can be entered into a specific field. In many experienced, they are very rarely used. However, these simple checks, entered at the time of database table creation, can provide additional safe guards against &#8216;bad&#8217; data getting into your database tables, either via errors in code or simply user area. SQL check constraints can act as a last line of defence against &#8216;bad&#8217; data, as it is verification at the database level.</p>
<p>You can create a table with a check constraint in MySQL as follows. The check in this example disallows values of the &#8216;P_Id&#8217; field from falling outside of the condition &#8216;P_Id&gt;0&#8242;. In other words, the &#8216;P_Id&#8217; field&#8217;s values must almost be greater than zero in order for the data to be accepted into the table by the database management system (DBMS).</p>
<pre>CREATE TABLE Persons
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
CHECK (P_Id&gt;0)
)</pre>
<p>You are probably wondering how to add a constraint to an existing database table. This is quite easy, and uses an &#8216;ALTER TABLE&#8217; SQL query. See the following example for how to add a check constraint to one of your existing database tables.</p>
<pre>ALTER TABLE Persons
ADD CHECK (P_Id&gt;0)</pre>
<p>For more information, there are other highly useful example queries relating to SQL check constraints at the relevant <a href="http://www.w3schools.com/Sql/sql_check.asp">SQL check constraint article</a> on <a href="http://www.w3schools.com/">W3schools</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jordanhall.co.uk/general-articles/sql-check-constraints-on-mysql-databases-2102526/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

