<?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>This is not a mundane detail, Michael. &#187; php</title>
	<atom:link href="http://blog.mikejestes.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mikejestes.com</link>
	<description></description>
	<lastBuildDate>Tue, 09 Jun 2009 22:05:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Flash for mac is bad for your HTTP_HOST</title>
		<link>http://blog.mikejestes.com/2008/04/18/flash-for-mac-is-bad-for-your-http_host/</link>
		<comments>http://blog.mikejestes.com/2008/04/18/flash-for-mac-is-bad-for-your-http_host/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 19:05:02 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[www]]></category>

		<guid isPermaLink="false">http://blog.mikejestes.com/?p=143</guid>
		<description><![CDATA[I&#8217;ve been testing the super awesome swfupload code for some projects at work. I have nice progress bars working and you can queue up multiple files. It&#8217;s sweet. I tested out my code in Opera, Firefox, Safari 3, IE 7, etc on Windows and Linux. Working great. Of course, an hour before an important meeting [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been testing the super awesome <a href="http://swfupload.org/">swfupload</a> code for some projects at work. I have nice progress bars working and you can queue up multiple files. It&#8217;s sweet. I tested out my code in Opera, Firefox, Safari 3, IE 7, etc on Windows and Linux. Working great.</p>
<p>Of course, an hour before an important meeting is when we discover it doesn&#8217;t work on any mac browser. The flash debug output shows our site initialization code is just throwing a fit. No DB access settings can be found. Doesn&#8217;t make any sense why an HTTP request from flash on a mac would break our app.</p>
<p>Here&#8217;s the basics of how our our setup switches dev/production settings:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#8216;HTTP_HOST&#8217;</span><span class="br0">&#93;</span> == <span class="st0">&#8216;example.mydesktop&#8217;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// LOCAL DEV SETTINGS</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#8216;HTTP_HOST&#8217;</span><span class="br0">&#93;</span> == <span class="st0">&#8216;example.com&#8217;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// PRODUCTION SITE SETTINGS</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>It makes considerations for www. etc.  The problem in this case is that flash is adding :80 to the HTTP Host header.  Instead of</p>
<pre>GET /path/to/file HTTP/1.1
Host: example.com</pre>
<p>Flash for mac likes to add</p>
<pre>GET /path/to/file HTTP/1.1
Host: example.com:80</pre>
<p>This will cause &#8216;example.com:80&#8242; to show up in the php $_SERVER['HTTP_HOST'] variable.  You can see how this would break simple host detection.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikejestes.com/2008/04/18/flash-for-mac-is-bad-for-your-http_host/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extending PEAR&#8217;s DB class</title>
		<link>http://blog.mikejestes.com/2006/01/09/extending-pears-db-class/</link>
		<comments>http://blog.mikejestes.com/2006/01/09/extending-pears-db-class/#comments</comments>
		<pubDate>Tue, 10 Jan 2006 02:42:32 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.mikejestes.com/2006/01/09/extending-pears-db-class/</guid>
		<description><![CDATA[This took me quite a while to figure out, so I probably should write it down. My basic goal was to have global db error handling by overloading the query method. Because of the inheritance heirarchy in the DB classes this was tough to nail down at first. Using the DB class in it&#8217;s vanila [...]]]></description>
			<content:encoded><![CDATA[<p>This took me quite a while to figure out, so I probably should write it down.  My basic goal was to have global db error handling by overloading the query method.  Because of the inheritance heirarchy in the DB classes this was tough to nail down at first.  Using the DB class in it&#8217;s vanila form looks like this:</p>
<pre>require_once('DB.php');
$db =&#038; DB::connect("mysql://user:pass@host/dbname");
$sql = "SELECT * FROM foo";
$query = $db->query($sql);
$result = $query->fetchRow();</pre>
<p>Which is a slightly different API than the DB class I was using at ResTek for a long time:</p>
<pre>require_once('DB.php');
$db = new db('database');
$sql = "SELECT * FROM foo";
$query = $db->query($sql);
$result = $db->fetch_assoc($query);</pre>
<p>It was a little annoying to rewrite code / retrain my brain for PEAR&#8217;s API, but it makes things easier.</p>
<p>Now when you call <code>DB::connect</code>, you do not get a DB object back but a DB_mysql (or whatever DB you specified).  I tried making my own MY_DB class to return the right objects.  Disaster.  I was successful with copying and renaming the classes DB, DB_common, and DB_mysql.  Now I was able to insert my own code in the <code>DB_mysql::query</code> method.  Sweet.</p>
<p>I eventually trimmed it down to just extending the DB_mysql class.  Here&#8217;s a sniplet that works very well for me:</p>
<pre>class DB_MIKE_mysql extends DB_mysql {

    function &#038;query($sql) {

        $query =&#038; DB_mysql::query($sql);

        if ($this->isError($query)) {

            /* custom error code here */

        }

        return $query;
    }
}

$db =&#038; DB::connect("MIKE_mysql://user:pass@host/dbname");</pre>
<p>The <code>DB::connect</code> function loads a class called DB_$WHATS_IN_THE_DSN, so getting the custom class name right was the tricky part.  PEAR seems to like this on php4 and php5.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikejestes.com/2006/01/09/extending-pears-db-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
