<?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>Francois Faubert &#187; MySQL</title>
	<atom:link href="http://www.francoisfaubert.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.francoisfaubert.com</link>
	<description></description>
	<lastBuildDate>Tue, 08 Sep 2009 19:00:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Stop reinventing the wheel</title>
		<link>http://www.francoisfaubert.com/2007/11/08/stop-reinventing-the-wheel/</link>
		<comments>http://www.francoisfaubert.com/2007/11/08/stop-reinventing-the-wheel/#comments</comments>
		<pubDate>Thu, 08 Nov 2007 15:20:34 +0000</pubDate>
		<dc:creator>francoisfaubert</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PDO]]></category>

		<guid isPermaLink="false">http://fake.themusictank.com/2007/11/08/stop-reinventing-the-wheel/</guid>
		<description><![CDATA[For years, I&#8217;ve been using an early version of a PHP database access class written by a friend of mine (hi Max!). I&#8217;ve been tweaking it over and over again, spending way too much time on it considering the end result.
Well I&#8217;m tired of reinventing the wheel. Since it&#8217;s fifth installment, PHP provides an API [...]]]></description>
			<content:encoded><![CDATA[<p>For years, I&#8217;ve been using an early version of a PHP database access class written by a friend of mine (hi Max!). I&#8217;ve been tweaking it over and over again, spending way too much time on it considering the end result.</p>
<p>Well I&#8217;m tired of reinventing the wheel. Since it&#8217;s fifth installment, PHP provides an API easing access to all types of databases called <a href="http://ca.php.net/manual/en/ref.pdo.php">PDO functions</a>. All the features you need are in there, coded in C by NASA engineers and is likely better than anything I could come up with.</p>
<p>You really should read up on the PDO if you currently maintain a custom database access object &#8212; or none at all. Also, as the documentation points out, this is not a full-blown database abstraction layer (to run MySQL, Oracle or others transparently) it&#8217;s a data-access abstraction layer (so make sure your queries are properly formed for the database you want to use).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.francoisfaubert.com/2007/11/08/stop-reinventing-the-wheel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Saving PHP Sessions to MySQL</title>
		<link>http://www.francoisfaubert.com/2007/06/16/saving-php-sessions-to-mysql/</link>
		<comments>http://www.francoisfaubert.com/2007/06/16/saving-php-sessions-to-mysql/#comments</comments>
		<pubDate>Sat, 16 Jun 2007 20:23:24 +0000</pubDate>
		<dc:creator>francoisfaubert</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[The Music Tank]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Sessions]]></category>

		<guid isPermaLink="false">http://fake.themusictank.com/2007/06/16/saving-php-sessions-to-mysql/</guid>
		<description><![CDATA[In most cases, websites don&#8217;t necessarily need to be managed by sessions that end as soon as the users closes their browser. Most websites now offer to keep their session alive for whatever amount of time. This is really less of a hassle for your users and adds to the positive user experience.
Learning what not [...]]]></description>
			<content:encoded><![CDATA[<p>In most cases, websites don&#8217;t necessarily need to be managed by sessions that end as soon as the users closes their browser. Most websites now offer to keep their session alive for whatever amount of time. This is really less of a hassle for your users and adds to the positive user experience.</p>
<p><strong>Learning what not to do </strong></p>
<p>On TMT, I used to handle sessions manually by storing the encrypted value of the user&#8217;s id in a cookie. That&#8217;s is highly unrecommended for security reasons as its fairly easy to hack your way around using an id that isn&#8217;t yours (and which might be the administrator&#8217;s!). </p>
<p>I experimented by storing so-called &#8216;unique&#8217; values I generated and stored in MySQL to have better validation when decrypting the cookie, but since you can spoof most $_SERVER values (which provides the user&#8217;s IP), it really wasn&#8217;t good enough.</p>
<p><strong>Hardcore PHP-ing</strong></p>
<p>You can override the whole session object using PHP&#8217;s <code><a href="http://www.php.net/manual/en/function.session-set-save-handler.php">session_set_save_handler()</a></code> function. Basically, you re-program what the object does when it reads and writes session values or when it destroys itself.</p>
<p>Instead of writing the session values to a file on the server like the default behavior is set to do, you can redirect the data handling to an insert or update query in your favorite database.</p>
<p><strong>Advantages</strong></p>
<p>The most obvious advantage is that you can keep the sessions alive as long as your server is live, more or less. You can also change the condition of how session expiration are done. For instance, through a simple MySQL query, TMT sessions can be kept for one week before being destroyed if no activity is logged.</p>
<p>I&#8217;ve read it&#8217;s safer to store session values that way too, as a possible hacker would need the database&#8217;s password to access it. While I&#8217;m not sure how harder this method actually makes it for hackers in reality, I really feel safer to use PHP&#8217;s native object rather than a shaky class I would have written.</p>
<p>Fully using PHP&#8217;s native session object allows more flexibility as you are very close to Apache. You can therefore validate with confidence (not blind confidence though) that the user is indeed human and not a spam bot, save the user&#8217;s preferred language or do whatever else your website offers as possible features without fear. In my previous horrible system, it wasn&#8217;t even a possibility.</p>
<p><strong>Examples</strong></p>
<p>Apart from <em>stalker at ruun dot de</em>&#8217;s very good comment on PHP.net&#8217;s documentation page, I found <a href="http://www.tonymarston.net/php-mysql/session-handler.html">Tony Marston</a>&#8217;s version of the object. The latter is harder to grasp as he uses his own object-oriented system to get database data &#8212; that&#8217;s good practice, but a bit harder to learn from. You can also see TMT&#8217;s class in our <a href="http://themusictank.svn.sourceforge.net/viewvc/themusictank/trunk/brain/php_Session.php?revision=22&amp;view=markup">SVN repository</a>.</p>
<p>The important thing is just to understand what you&#8217;re trying to do rather than copy pasting each of our codes. TMT&#8217;s only started working once I grasped the concept.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.francoisfaubert.com/2007/06/16/saving-php-sessions-to-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Do you remember my table structure?</title>
		<link>http://www.francoisfaubert.com/2006/11/16/do-you-remember-my-table-structure/</link>
		<comments>http://www.francoisfaubert.com/2006/11/16/do-you-remember-my-table-structure/#comments</comments>
		<pubDate>Thu, 16 Nov 2006 15:13:49 +0000</pubDate>
		<dc:creator>francoisfaubert</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[The Music Tank]]></category>
		<category><![CDATA[Backups]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://fake.themusictank.com/2006/11/16/do-you-remember-my-table-structure/</guid>
		<description><![CDATA[I think the worst part of the whole host transfer deal was the relatively old age of my last MySQL backup. I always keep updated versions of my PHP files close by, may it only be because I am always working on something new, so at least all the programming logic has migrated successfully.
However, all [...]]]></description>
			<content:encoded><![CDATA[<p>I think the worst part of the whole host transfer deal was the relatively old age of my last MySQL backup. I always keep updated versions of my PHP files close by, may it only be because I am always working on something new, so at least all the programming logic has migrated successfully.</p>
<p>However, all the tables and database structure I had built stayed with Abnormis. Hopefully my old server will come back online and I will be able to get some of the file content back, but I am really just interested in how I had built my tables &#8212; which I don&#8217;t think I&#8217;ll be able to access. I don&#8217;t even remember most lengths and data types of the columns. Even my PHP source code can&#8217;t give me much hints at the moment.</p>
<p>At least this morning I was able to reconnect the user table. This means future posters and tankers can already join the Tank&#8230; and do nothing afterwards. Hopefully I&#8217;ll have the news working by early afternoon.</p>
<p>The moral of the story is that a backup, when you are developing,  is always too old.</p>
<p>And damn do I need to fix the transparent issues with IE 6 as soon as possible!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.francoisfaubert.com/2006/11/16/do-you-remember-my-table-structure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
