<?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>Jeremy Moseley &#187; Tips</title>
	<atom:link href="http://jeremymoseley.com/categories/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://jeremymoseley.com</link>
	<description>Application Development Blog</description>
	<lastBuildDate>Tue, 13 Jul 2010 06:40:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Autoloading Classes</title>
		<link>http://jeremymoseley.com/2010/06/23/autoloading-classes/</link>
		<comments>http://jeremymoseley.com/2010/06/23/autoloading-classes/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 07:51:39 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://jeremymoseley.com/?p=54</guid>
		<description><![CDATA[For those PHP coders out there that are starting to use OOP, if you don&#8217;t know about the autoload function, read on. It is simple to instantiate objects anywhere in your code without having to worry if the class has &#8230; <a href="http://jeremymoseley.com/2010/06/23/autoloading-classes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For those PHP coders out there that are starting to use OOP, if you don&#8217;t know about the autoload function, read on.<span id="more-54"></span></p>
<p>It is simple to instantiate objects anywhere in your code without having to worry if the class has been included by using the __autoload function. When working with autoload you must have a naming convention that you will stick with. Throughout this example I will provide my naming conventions, but feel free to modify it to suit your style.</p>
<p>Create a directory in your webroot called &#8220;lib&#8221;. This will contain all your class files as well as an include file which we will be creating shortly. Name all your class files with the exact same name as the class except in lowercase letters, followed by &#8220;.class.php&#8221;. So for your Product class it would be named, &#8220;product.class.php&#8221;.</p>
<p>Now create a file called include.php in your lib directory with the following code:</p>
<pre class="brush:php">function __autoload($name){
	$path = pathinfo(__FILE__);
	$name = strtolower($name);
	include_once("{$path['dirname']}/{$name}.class.php");
}</code></pre>
<p>Create an index.php file in your webroot and include the lib/include.php file you just created. You can now instantiate any object that is available to you in your library of classes without having to manually include each class. Cool, huh?!</p>
<pre class="brush:php">include_once('lib/include.php');
$object = new Class();</pre>
]]></content:encoded>
			<wfw:commentRss>http://jeremymoseley.com/2010/06/23/autoloading-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dealing with MySQL Date</title>
		<link>http://jeremymoseley.com/2009/10/02/dealing-with-mysql-date/</link>
		<comments>http://jeremymoseley.com/2009/10/02/dealing-with-mysql-date/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 07:48:04 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Solution]]></category>

		<guid isPermaLink="false">http://jeremymoseley.com/?p=25</guid>
		<description><![CDATA[Working with dates can be a pain, especially if you are storing them in a database. In the quick example you will learn the basics of the date, strtotime, and mktime functions to convert your dates to be stored in &#8230; <a href="http://jeremymoseley.com/2009/10/02/dealing-with-mysql-date/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Working with dates can be a pain, especially if you are storing them in a database. In the quick example you will learn the basics of the date, strtotime, and mktime functions to convert your dates to be stored in a MySQL database and to retrieve the date from the database and display it in a nice format for the end user to see.<span id="more-25"></span></p>
<p>Assuming you are using MySQL as your database, a data type of &#8216;date&#8217; is stored as &#8216;YYYY-MM-DD&#8217;. In PHP we can represent the MySQL date data type by using the <a href="http://us3.php.net/manual/en/function.date.php" target="_blank">date()</a> function like so.</p>
<pre class="brush:php;">echo date('Y-m-d'); //2010-10-02</pre>
<p>To convert a stored date in a MySQL database to a user friendly format, use the <a href="http://us3.php.net/manual/en/function.strtotime.php" target="_blank">strtotime()</a> function to convert the date retrieved from the database into seconds. You will use this as the second parameter for the <a href="http://us3.php.net/manual/en/function.date.php" target="_blank">date()</a> function that contains a string of how you want the date formatted. Check out the PHP manual&#8217;s date function page for a full list of what all the letter represent. </p>
<pre class="brush:php;">$db_date = '2010-10-02'; //MySQL date format
echo date('F j, Y', strtotime($db_date)); //October 2, 2010</pre>
<p>When converting dates for entry into a database, you will likely collect the year, month, and date from a form as separate variables. If this is the case you can easily convert the variables into a MySQL ready date by using the <a href="http://us3.php.net/manual/en/function.mktime.php" target="_blank">mktime()</a> function.</p>
<pre class="brush:php;">$year = 2010;
$month = 10;
$day = 2; //notice the 2 is not padded with a zero
$db_date = date('Y-m-d', mktime(0, 0, 0, $month, $day, $year));
echo $db_date; //2010-10-02</pre>
<p>If you are using time in your code, the date function will handle time as well. The corresponding MySQL data type is &#8220;datetime&#8221;.</p>
<pre class="brush:php;">echo date('Y-m-d H:i:s'); //2010-10-02 00:32:15</pre>
]]></content:encoded>
			<wfw:commentRss>http://jeremymoseley.com/2009/10/02/dealing-with-mysql-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

