<?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>Patrick Hartman &#187; php</title>
	<atom:link href="http://www.patrickhartman.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.patrickhartman.com</link>
	<description>web development, photoshop scripting and other thoughts</description>
	<lastBuildDate>Thu, 18 Feb 2010 06:57:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MySQL connection string for multiple servers in PHP</title>
		<link>http://www.patrickhartman.com/2009/10/03/mysql-connection-string-for-multiple-servers/</link>
		<comments>http://www.patrickhartman.com/2009/10/03/mysql-connection-string-for-multiple-servers/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 10:56:59 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.patrickhartman.com/?p=33</guid>
		<description><![CDATA[This is something that I started doing recently that I have found really helpful. Whenever I have a MySQL include file for a web development project, I set it up so it will work on both my local dev server and the live website. I accomplish this by checking to see where the file is [...]]]></description>
			<content:encoded><![CDATA[<p>This is something that I started doing recently that I have found really helpful. Whenever I have a MySQL include file for a web development project, I set it up so it will work on both my local dev server and the live website. I accomplish this by checking to see where the file is being loaded from &#8211; if it is being loaded from the web server, you just connect to localhost; if it is being loaded somewhere else, it will use the domain name to access the database server.</p>
<pre class="brush: php">
// define your settings
$domain = "example.com";
$user = "dblogin";
$pass = "dbpassword";
$schema = "dbname";

// check to see where this is being loaded from
if ($_SERVER['HTTP_HOST'] == "$domain" || $_SERVER['HTTP_HOST'] == "www.$domain") {
	// if loaded off website, connect to localhost
	$link = mysqli_connect("localhost", $user, $pass, $schema) or die(mysqli_error());
} else {
	// otherwise you will need to access it remotely
	$link = mysqli_connect($domain, $user, $pass, $schema) or die(mysqli_error());
}

// check your connection
if (mysqli_connect_errno()) {
	printf("Connect failed: %s\n", mysqli_connect_error());
	exit();
}
</pre>
<p>This works great because you have have the exact same files on both servers, when you deploy changes to the site you don&#8217;t need to worry about removing your development server info.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patrickhartman.com/2009/10/03/mysql-connection-string-for-multiple-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check if time falls between a range in PHP</title>
		<link>http://www.patrickhartman.com/2009/08/29/check-if-time-falls-between-a-range-in-php/</link>
		<comments>http://www.patrickhartman.com/2009/08/29/check-if-time-falls-between-a-range-in-php/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 16:31:00 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.patrickhartman.com/?p=27</guid>
		<description><![CDATA[I was digging through some old stuff today and found this PHP function I wrote awhile back. You pass a time to the function along with a start time and end time, and it will determine if the time falls between that range. I figured I would post it on here in case anyone has [...]]]></description>
			<content:encoded><![CDATA[<p>I was digging through some old stuff today and found this PHP function I wrote awhile back. You pass a time to the function along with a start time and end time, and it will determine if the time falls between that range. I figured I would post it on here in case anyone has a need for it.</p>
<pre class="brush: php;">
function CheckTime($currentTime, $startTime, $endTime){
	// written 11/26/2006 by Patrick H. (patrickh@gmail.com)
	//
	// the time passed must meet all the below criteria to return 1 (true):
	//
	// - current hour needs to be equal or greater than start hour
	// - current hour needs to be equal or less than end hour
	// - current minute needs to be equal or greater than start minute (if current hour is ok)
	// - current minute needs to be equal or less than end minute (if current hour is ok)
	//
	// if any of those checks does not pass, it will return 0 (false)

	global $cHour;
	global $cMin;
	global $sHour;
	global $sMin;
	global $eHour;
	global $eMin;

	// break up current time
	$now = explode(":",$currentTime);
	$cHour = intval($now[0]);	// current time - hour
	$cMin = intval($now[1]);	// current time - minute

	// break up start time
	$start = explode(":",$startTime);
	$sHour = intval($start[0]);	// start of range - hour
	$sMin = intval($start[1]);	// start of range - minute

	// brek up end time
	$end = explode(":",$endTime);
	$eHour = intval($end[0]);	// end of range - hour
	$eMin = intval($end[1]);	// end of range - minute

	// this is the variable used to track the result of the checks
	$pass = true;

	if($sHour < $eHour){
		// the range is on the same day

		// compare to the start hour
		if($cHour < $sHour){
			$pass = false;
		};

		// compare to the end hour
		if($cHour > $eHour){
			$pass = false;
		};

		// compare to the start min
		if($cHour == $sHour){
			if($cMin < $sMin){
				$pass = false;
			};
		};

		// compare to the end min
		if($cHour == $eHour){
			if($cMin > $eMin){
				$pass = false;
			};
		};

	} else {
		// the range is overnight, so the logic is a little different

		if( ($cHour < $sHour) &#038;&#038; ($cHour > $eHour) ){
			$pass = false;
		};

		// compare to the start min
		if($cHour == $sHour){
			if($cMin < $sMin){
				$pass = false;
			};
		};

		// compare to the end min
		if($cHour == $eHour){
			if($cMin > $eMin){
				$pass = false;
			};
		};

	};

	// done with check, return the result
	if($pass == false){
		return 0;	// failed
	} else {
		return 1;	// passed
	};

};

// test it out
// make sure you use military time
// usage: current time, range start time, range end time

echo CheckTime("06:30","15:20","06:45");	// this should return 1
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.patrickhartman.com/2009/08/29/check-if-time-falls-between-a-range-in-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
