<?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>James F. Roberts IV</title>
	<atom:link href="http://jamesroberts.name/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://jamesroberts.name/blog</link>
	<description>figuring out internettings, one line of code at a time...</description>
	<lastBuildDate>Thu, 10 May 2012 23:22:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Upstream timeout issues with nginX + php-fpm + CodeIgniter + gzip + xdebug on DotCloud &#8211; [resolved]</title>
		<link>http://jamesroberts.name/blog/2012/05/10/upstream-timeout-issues-with-nginx-php-fpm-codeigniter-gzip-xdebug-on-dotcloud-resolved/</link>
		<comments>http://jamesroberts.name/blog/2012/05/10/upstream-timeout-issues-with-nginx-php-fpm-codeigniter-gzip-xdebug-on-dotcloud-resolved/#comments</comments>
		<pubDate>Thu, 10 May 2012 23:14:59 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[DotCloud]]></category>
		<category><![CDATA[gzip]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[ob_gzhandler]]></category>
		<category><![CDATA[php-fpm]]></category>
		<category><![CDATA[seg fault]]></category>
		<category><![CDATA[upstream timeout]]></category>
		<category><![CDATA[xdebug]]></category>

		<guid isPermaLink="false">http://jamesroberts.name/blog/?p=197</guid>
		<description><![CDATA[We have been using DotCloud as our hosting platform for months now, and overall I have been extremely pleased with their service.  There were some bumps in the road early on while they were still in their beta phase, but things have been running very smoothly for a few months now.  Everything except an uncomfortable [...]]]></description>
			<content:encoded><![CDATA[<p>We have been using DotCloud as our hosting platform for months now, and overall I have been extremely pleased with their service.  There were some bumps in the road early on while they were still in their beta phase, but things have been running very smoothly for a few months now.  Everything except an uncomfortable number of seemingly random nginX &#8220;upstream timed out (110: Connection timed out) while reading response header from upstream&#8221; errors.</p>
<p>If you want to get what you need and not read the rest of this post, I will make it super simple for you: <strong></strong></p>
<h3><strong>If you are using php-fpm, <strong>gzip, xdebug </strong> and <strong>CodeIgniter</strong>, disable xdebug!!!</strong></h3>
<p>For anyone who feels like listening to my story, please read on.  Not only were these errors unsettling, but they were causing DotCloud&#8217;s load balancer to bounce POST requests  back to our servers multiple times because it was getting error responses and assuming nothing was happening on our end.  This in turn was causing user input (comments, image uploads, password requests, etc) to be saved (or emails sent) on our application multiple times.  Super embarrassing.</p>
<p>After weeks of research and floundering, a DotCloud tech and I finally discovered the issue.  There is a known bug with xdebug and ob_gzhandler which was causing our php processes to seg fault.  The bug is documented here:</p>
<p><a href="http://grokbase.com/p/php/php-bugs/0365rtcdgx/23985-bgs-ob-gzhandler-make-segmentation-fault">http://grokbase.com/p/php/php-bugs/0365rtcdgx/23985-bgs-ob-gzhandler-make-segmentation-fault</a></p>
<p>What was happening was the request was sent to our server, the php process was doing everything it was supposed to, then when CodeIgniter&#8217;s output buffer was being gzipped by ob_gziphandler(), the php process was segmentation faulting and causing nginx to time out waiting for the response from php-fpm.  So, while everything was successfully happening in the php script, the output back to the client was failing.</p>
<p>By disabling the xdebug extension in the php configuration, the php processes stopped seg faulting, and everything is happy again!  No more Upstream Timeouts! It took a really long time to track this issue down, so I hope this post helps someone =)</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesroberts.name/blog/2012/05/10/upstream-timeout-issues-with-nginx-php-fpm-codeigniter-gzip-xdebug-on-dotcloud-resolved/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AddThis Pintrest button hack to look better in 32&#215;32 format</title>
		<link>http://jamesroberts.name/blog/2012/04/30/addthis-pintrest-button-hack-to-look-better-in-32x32-format/</link>
		<comments>http://jamesroberts.name/blog/2012/04/30/addthis-pintrest-button-hack-to-look-better-in-32x32-format/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 22:17:37 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://jamesroberts.name/blog/?p=192</guid>
		<description><![CDATA[Today I had to add a Pinterest Share button on our website, and run it through our AddThis account so we can track the analytics.  Unfortunately, there are only two options for the Pinterest button via AddThis, neither of which look good along side our 32&#215;32 style share buttons.  So, I decided to hack it [...]]]></description>
			<content:encoded><![CDATA[<p>Today I had to add a Pinterest Share button on our website, and run it through our AddThis account so we can track the analytics.  Unfortunately, there are only two options for the Pinterest button via AddThis, neither of which look good along side our 32&#215;32 style share buttons.  So, I decided to hack it up =)</p>
<p>If you apply a fixed height to the a tag which holds the Pinterest button&#8217;s iframe, then set overflow to hidden, then apply a negative margin to the nested iframe, you can essentially get rid of that pesky count bubble that will not go away.</p>
<p>Resulting css is something like:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&nbsp;
	<span style="color: #6666ff;">.addthis_toolbox</span> <span style="color: #00AA00;">&gt;</span> a.addthis_button_pinterest_pinit<span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">8px</span> <span style="color: #933;">0px</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">24px</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">baseline</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
	<span style="color: #6666ff;">.addthis_toolbox</span> <span style="color: #00AA00;">&gt;</span> a<span style="color: #6666ff;">.addthis_button_pinterest_pinit</span> &amp;gt<span style="color: #00AA00;">;</span> iframe<span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">-34px</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://jamesroberts.name/blog/2012/04/30/addthis-pintrest-button-hack-to-look-better-in-32x32-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mongodb geospatial query example in php with distance radius in miles and km</title>
		<link>http://jamesroberts.name/blog/2012/03/12/mongodb-geospatial-query-example-in-php-with-distance-radius-in-miles-and-km/</link>
		<comments>http://jamesroberts.name/blog/2012/03/12/mongodb-geospatial-query-example-in-php-with-distance-radius-in-miles-and-km/#comments</comments>
		<pubDate>Mon, 12 Mar 2012 06:44:07 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[mongodb]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[geospatial]]></category>
		<category><![CDATA[lat]]></category>
		<category><![CDATA[lng]]></category>
		<category><![CDATA[mongodb query]]></category>

		<guid isPermaLink="false">http://jamesroberts.name/blog/?p=185</guid>
		<description><![CDATA[Recently for a project involving 311 reports in New York city, I had to find a speedy way to query over 3 million records within a certain radius of a latitude longitude point. Mysql is slow for this sort of thing, so I decided to try the data set out with Solr. Solr worked great [...]]]></description>
			<content:encoded><![CDATA[<p>Recently for a project involving 311 reports in New York city, I had to find a speedy way to query over 3 million records within a certain radius of a latitude longitude point.  Mysql is slow for this sort of thing, so I decided to try the data set out with Solr.  Solr worked great and was quite responsive, but required a massive amount of RAM on our server to hold the entire dataset.  This was &#8220;ok&#8221; for our current dataset, but what would happen when we started to expand beyond NYC? or if we kept adding on new 311 reports from NYC as they come in over time?  Solr was not scaleable.  Mongodb to the rescue!</p>
<p>I wrote a simple import script in PHP to pull in the data we had already imported into mysql into mongodb.  The only special part of the data mirgation was the creation of a &#8220;lnglat&#8221; field in each imported document array which is a &#8220;2d index&#8221; in mongo.  You have to set a multivalued field with the lat/lng values cast as floats in the document array, like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$doc</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lnglat'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lng'</span><span style="color: #339933;">=&gt;</span><span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lng'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'lat'</span><span style="color: #339933;">=&gt;</span><span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lat'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>After the data has been imported to mongo, you create the 2d index on that multivalued field using the mongo command line, with this command:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">my_mongodb.<span style="color: #660066;">my_collection</span>.<span style="color: #660066;">ensureIndex</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span> lnglat <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;2d&quot;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span></pre></div></div>

<p>Once I had the data in mongo, I had a hard time finding good examples of Geospatial queries for mongodb in php.  I finally found this page:<br />
<a href="http://comments.gmane.org/gmane.comp.db.mongodb.user/48789" title="http://comments.gmane.org/gmane.comp.db.mongodb.user/48789" target="_blank">http://comments.gmane.org/gmane.comp.db.mongodb.user/48789</a><br />
which solved all my problems and pointed out that when querying mongo with a lat/lng point as an array, mongodb expects the lng to be first, not the lat. Durrrr&#8230;</p>
<p>Anyway, here is the code snippit that I pulled from the <a href="http://comments.gmane.org/gmane.comp.db.mongodb.user/48789" title="useful php example of geospatial queries using mongodb with distance radius">url above</a> which was the first comprehensible example I found of php code for geospatial queries in with a distance radius specified:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getRadiusMiles<span style="color: #009900;">&#40;</span><span style="color: #000088;">$lng</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lat</span><span style="color: #339933;">,</span> <span style="color: #000088;">$radius</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$radiusOfEarth</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3956</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//avg radius of earth in miles</span>
	<span style="color: #000088;">$cursor</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">collection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lnglat'</span> <span style="color: #339933;">=&gt;</span>
			<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$within'</span> <span style="color: #339933;">=&gt;</span>
				<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$centerSphere'</span> <span style="color: #339933;">=&gt;</span>
					<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
						<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">floatval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lng</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">floatval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lat</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$radius</span><span style="color: #339933;">/</span><span style="color: #000088;">$radiusOfEarth</span>
					<span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$resultset</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">jsonCursor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cursor</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resultset</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getRadiusKm<span style="color: #009900;">&#40;</span><span style="color: #000088;">$lng</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lat</span><span style="color: #339933;">,</span> <span style="color: #000088;">$radius</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$radiusOfEarth</span> <span style="color: #339933;">=</span> <span style="color:#800080;">6378.1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//avg radius of earth in km</span>
	<span style="color: #000088;">$cursor</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">collection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lnglat'</span> <span style="color: #339933;">=&gt;</span>
			<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$within'</span> <span style="color: #339933;">=&gt;</span>
				<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$centerSphere'</span> <span style="color: #339933;">=&gt;</span>
					<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
						<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">floatval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lng</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">floatval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lat</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$radius</span><span style="color: #339933;">/</span><span style="color: #000088;">$radiusOfEarth</span>
					<span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$resultset</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">jsonCursor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cursor</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resultset</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Hopefully this saves someone some time!</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesroberts.name/blog/2012/03/12/mongodb-geospatial-query-example-in-php-with-distance-radius-in-miles-and-km/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysqldump 5.1.36 unable to successfully dump a MySQL database in UTF-8 character encoding issues</title>
		<link>http://jamesroberts.name/blog/2012/02/24/mysqldump-5-1-36-unable-to-successfully-dump-a-mysql-database-in-utf-8-character-encoding-issues/</link>
		<comments>http://jamesroberts.name/blog/2012/02/24/mysqldump-5-1-36-unable-to-successfully-dump-a-mysql-database-in-utf-8-character-encoding-issues/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 01:53:44 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[character encoding]]></category>
		<category><![CDATA[mysql collation]]></category>

		<guid isPermaLink="false">http://jamesroberts.name/blog/?p=171</guid>
		<description><![CDATA[Today I had a character encoding problem when importing some data from a mysqldump from a contractor we had hired to do some work.  Everything about the dump was fine, the database, tables, and fields were all using utf8_unicode_ci utf8 collation, the dump file was encoded in utf8, and the database I was importing to [...]]]></description>
			<content:encoded><![CDATA[<p>Today I had a character encoding problem when importing some data from a mysqldump from a contractor we had hired to do some work.  Everything about the dump was fine, the database, tables, and fields were all using utf8_unicode_ci utf8 collation, the dump file was encoded in utf8, and the database I was importing to was all utf8 as well.  The contractor said he was able to re-import the dump into his server and local environment fine, but I was still unable to get the dump imported without all the utf8 characters getting garbled.  As it turns out, his mysql and mysqldump versions were older than mine and it was messing everything up.  Apparently, according to this mysql bug post:</p>
<p><a href="http://bugs.mysql.com/bug.php?id=28969" target="_blank">http://bugs.mysql.com/bug.php?id=28969</a></p>
<p>&#8220;As of today (Feb 6, 2012) mysqldump 5.1.36 still exhibits the faulty behavior (unable to successfully dump a MySQL database in UTF-8)&#8221;.  We were able to fix this issue by following these steps:</p>
<ol>
<li>add latin1 default character set to the mysql dump command from the older versioned database, like so:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysqldump <span style="color: #660033;">-u</span> dbuser <span style="color: #660033;">-p</span> <span style="color: #660033;">--default-character-set</span>=latin1 my_database_name <span style="color: #000000; font-weight: bold;">&gt;</span> db_dump.sql</pre></div></div>

<p>You can also try adding a &#8220;-r&#8221; flag to this command which should allow non-latin characters to dump properly as well, but this did not work in our case.
</li>
<li>before importing into the newer version database, open the in the newly created dump file and change the line that reads:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/*!</span><span style="color: #000000;">40101</span> SET NAMES latin1 <span style="color: #000000; font-weight: bold;">*/</span>;</pre></div></div>

<p> to:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/*!</span><span style="color: #000000;">40101</span> SET NAMES utf8 <span style="color: #000000; font-weight: bold;">*/</span>;</pre></div></div>

<p> then save the file</li>
<li>import to the newer version database using:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysql <span style="color: #660033;">-u</span> dbuser <span style="color: #660033;">-p</span> <span style="color: #660033;">--default-character-set</span>=utf8 my_database_name <span style="color: #000000; font-weight: bold;">&lt;</span> db_dump.sql</pre></div></div>

</li>
</ol>
<p>Took a lot of emails back and forth to finally come to this solution.  Hopefully this helps some one and thank god for the original bug post linked above!</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesroberts.name/blog/2012/02/24/mysqldump-5-1-36-unable-to-successfully-dump-a-mysql-database-in-utf-8-character-encoding-issues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>disable firefox native inspect element context menu</title>
		<link>http://jamesroberts.name/blog/2012/02/07/disable-firefox-native-inspect-element-context-menu/</link>
		<comments>http://jamesroberts.name/blog/2012/02/07/disable-firefox-native-inspect-element-context-menu/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 18:26:19 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://jamesroberts.name/blog/?p=166</guid>
		<description><![CDATA[With the latest update of Firefox to version 10.0, they included some new developer tools which are similar to what is available via Firebug or WebKit&#8217;s developer tools.  About time!  Unfortunately, I still am so used to firebug that will continue using it instead of these new native development tools.  One thing that really grinds [...]]]></description>
			<content:encoded><![CDATA[<p>With the latest update of Firefox to version 10.0, they included some new developer tools which are similar to what is available via Firebug or WebKit&#8217;s developer tools.  About time!  Unfortunately, I still am so used to firebug that will continue using it instead of these new native development tools.  One thing that really grinds my gears was the native &#8220;Inspect Element&#8221; context menu item because it lives directly above the Firebug one.  This was extremely frustrating for me because I kept clicking on that instead of the &#8220;Inspect with Firebug&#8221; menu item.  This would bring up the native inspector console, which I would then have to close, then go back and right click again and make sure I click on the inspect with firebug menu item.  Sigh&#8230;..how annoying.</p>
<p>Anyway, there is a simple way to disable the native inspect element context menu item.  In the Firefox address bar, put &#8220;about:config&#8221; and press Enter.  This will bring up Firefox&#8217;s preference configurations.  In the &#8220;filter&#8221; search box enter &#8220;inspector&#8221;.  This will bring up three configuration preferences.  Simply double click on the &#8220;devtools.inspector.enabled&#8221; preference to change it to &#8220;false&#8221; and viola!  No more native inspect element in the context menu!  Horray.</p>
<p><a href="http://jamesroberts.name/blog/wp-content/uploads/2012/02/firefox-about-config-inspector.jpg"><img class="aligncenter size-full wp-image-169" title="firefox about config native inspect element" src="http://jamesroberts.name/blog/wp-content/uploads/2012/02/firefox-about-config-inspector.jpg" alt="" width="714" height="349" /></a></p>
<p>Don&#8217;t muck around in here too much or you will mess up your firefox configuration.  I hope someone finds this useful =)</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesroberts.name/blog/2012/02/07/disable-firefox-native-inspect-element-context-menu/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>php mysql collation change script</title>
		<link>http://jamesroberts.name/blog/2012/01/04/mysql-collation-change-script/</link>
		<comments>http://jamesroberts.name/blog/2012/01/04/mysql-collation-change-script/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 06:56:38 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[character encoding]]></category>
		<category><![CDATA[collation]]></category>

		<guid isPermaLink="false">http://jamesroberts.name/blog/?p=153</guid>
		<description><![CDATA[There are times when we get stuck with bad collations on our mysql tables and we are overwhelmed by having to change them by hand. Well, I have written a php script which will go through all your tables and fields in a database and update them to the collation which works for you. In [...]]]></description>
			<content:encoded><![CDATA[<p>There are times when we get stuck with bad collations on our mysql tables and we are overwhelmed by having to change them by hand.  Well, I have written a php script which will go through all your tables and fields in a database and update them to the collation which works for you.  In my case for this example, I have a database which contains a mix of collations and changes them all to utf8_unicode_ci.  This example uses the mysqli object in php as the database connection.  </p>
<p>Your will need to update the database connection credentials as they are all bogus in this example.  You will also need to change the &#8220;$execute_sql&#8221; to equal true if you want the script to actually perform the collation change via this script.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
	<span style="color: #000088;">$execute_sql</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'mydbhost'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'username'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'passsword'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$dbname</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'databasename'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> mysqli<span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbname</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$mysqldatabase</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'databasename'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$collation</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'CHARACTER SET utf8 COLLATE utf8_unicode_ci'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ALTER DATABASE <span style="color: #006699; font-weight: bold;">$mysqldatabase</span> <span style="color: #006699; font-weight: bold;">$collation</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SHOW TABLES&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$table</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Tables_in_'</span><span style="color: #339933;">.</span><span style="color: #000088;">$mysqldatabase</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$execute_sql</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ALTER TABLE <span style="color: #006699; font-weight: bold;">$table</span> DEFAULT <span style="color: #006699; font-weight: bold;">$collation</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$result1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SHOW COLUMNS FROM <span style="color: #006699; font-weight: bold;">$table</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$alter</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'~char|text|enum|set~'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row1</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;Type&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row1</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;Field&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'uuid'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">// why does this not work</span>
				<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$alter</span> <span style="color: #339933;">.=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$alter</span><span style="color: #009900;">&#41;</span>?<span style="color: #0000ff;">&quot;, <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">:</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;MODIFY `<span style="color: #006699; font-weight: bold;">$row1[Field]</span>` <span style="color: #006699; font-weight: bold;">$row1[Type]</span> <span style="color: #006699; font-weight: bold;">$collation</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row1</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;Null&quot;</span><span style="color: #009900;">&#93;</span> ? <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot; NOT NULL&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row1</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;Default&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$row1</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;Default&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;NULL&quot;</span> ? <span style="color: #0000ff;">&quot; DEFAULT '<span style="color: #006699; font-weight: bold;">$row1[Default]</span>'&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$alter</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ALTER TABLE <span style="color: #006699; font-weight: bold;">$table</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$alter</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div&gt;<span style="color: #006699; font-weight: bold;">$sql</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$execute_sql</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$count</span><span style="color: #339933;">++;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The only gotcha that I have run into with my script that I have yet to solve is that when you change the collation of an existing uuid field which has a foreign key, the copy table fails in mysql.  Not that the collation of a uuid field really matters, but you can see a comment in the routine which questions why this does not work.  </p>
<p>Anyway, I hope someone finds this useful =)  Enjoy&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesroberts.name/blog/2012/01/04/mysql-collation-change-script/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>MySQL alter table to re-order columns</title>
		<link>http://jamesroberts.name/blog/2011/10/02/mysql-alter-table-to-re-order-columns/</link>
		<comments>http://jamesroberts.name/blog/2011/10/02/mysql-alter-table-to-re-order-columns/#comments</comments>
		<pubDate>Sun, 02 Oct 2011 18:50:36 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://jamesroberts.name/blog/?p=146</guid>
		<description><![CDATA[Sometimes because of my completely anal nature, I want the fields that I&#8217;ve already added to a table in MySQL to be in a different order. To do this you can simply alter that table column, without changing any of its properties, then adding &#8220;AFTER column_3&#8243;. So for instance you had a table like this: [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes because of my completely anal nature, I want the fields that I&#8217;ve already added to a table in MySQL to be in a different order.  To do this you can simply alter that table column, without changing any of its properties, then adding &#8220;AFTER column_3&#8243;.</p>
<p>So for instance you had a table like this:</p>
<pre>
mysql> describe test;
+-----------+---------+------+-----+---------+----------------+
| Field     | Type    | Null | Key | Default | Extra          |
+-----------+---------+------+-----+---------+----------------+
| column_id | int(11) | NO   | PRI | NULL    | auto_increment |
| column_1  | int(11) | NO   |     | NULL    |                |
| column_2  | int(11) | NO   |     | NULL    |                |
| column_3  | int(11) | NO   |     | NULL    |                |
+-----------+---------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
</pre>
<p>But you really want column_1 to be ordered after column_3 because you are as ridiculous as I am.  You can run this query:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`test`</span> <span style="color: #993333; font-weight: bold;">CHANGE</span> <span style="color: #ff0000;">`column_1`</span> <span style="color: #ff0000;">`column_1`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">11</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NULL</span> AFTER column_3;</pre></div></div>

<p>Now your table looks like this:</p>
<pre>
mysql> describe test;
+-----------+---------+------+-----+---------+----------------+
| Field     | Type    | Null | Key | Default | Extra          |
+-----------+---------+------+-----+---------+----------------+
| column_id | int(11) | NO   | PRI | NULL    | auto_increment |
| column_2  | int(11) | NO   |     | NULL    |                |
| column_3  | int(11) | NO   |     | NULL    |                |
| column_1  | int(11) | YES  |     | NULL    |                |
+-----------+---------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
</pre>
<p>I find this to be useful for me on larger tables that have grown over time and I want some relevant columns grouped together for when I am viewing data in phpMyAdmin or whatever.</p>
<p>Hope this helps someone =)</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesroberts.name/blog/2011/10/02/mysql-alter-table-to-re-order-columns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS3 dual background glow highlight button</title>
		<link>http://jamesroberts.name/blog/2011/01/12/css3-dual-background-glow-highlight-button/</link>
		<comments>http://jamesroberts.name/blog/2011/01/12/css3-dual-background-glow-highlight-button/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 00:27:47 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[CSS3]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[multiple backgrounds]]></category>
		<category><![CDATA[rgba]]></category>

		<guid isPermaLink="false">http://jamesroberts.name/blog/?p=138</guid>
		<description><![CDATA[I have been working on a new UI at work and decided to go full on with it in HTML5 and CSS3 because its 98% for internal company users who all use a &#8220;modern browser&#8221; and I don&#8217;t have to worry about those pesky IE users. The following code is for a cool looking glow [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working on a new UI at work and decided to go full on with it in HTML5 and CSS3 because its 98% for internal company users who all use a &#8220;modern browser&#8221; and I don&#8217;t have to worry about those pesky IE users.  The following code is for a cool looking glow highlight button which involves multiple backgrounds with rgba color.  I have included three states: normal, hover, and active.</p>
<p>Enjoy!</p>
<p><button id="css3-button" type="button">Cool Arse Button</button></p>
<style>
button#css3-button{
	padding: 0.4em 1em 0.4em 1em;
	font-family:Helvetica, Arial, sans-serif;
	font-size:1.1em;
	color: #2885ab;
	letter-spacing:-0.05em;
	text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.4), 0px 0px 6px rgba(0, 0, 0, 0.2);
	font-weight:bold;
	cursor:pointer;
	border:1px solid #FFFFFF;
	-moz-border-radius: 0.7em;
	-webkit-border-radius: 0.7em;
	border-radius: 0.7em;
	background: -moz-linear-gradient(left, rgba(131, 182, 202,  0.8), rgba(131, 182, 202, 0.2) 15%, rgba(131, 182, 202, 0) 50%, rgba(131, 182, 202, 0.2) 85%, rgba(131, 182, 202, 0.8)),
				-moz-linear-gradient(top, #e2f4fb, #b5d4e0 50%, #b5d4e0 50%, #91bfd1);
	background: -webkit-gradient(linear, 0% 0%, 100% 0%, from(rgba(131, 182, 202, 0.8)), to(rgba(131, 182, 202, 0.8)), color-stop(.15, rgba(131, 182, 202, 0.2)), color-stop(.5, rgba(131, 182, 202, 0)), color-stop(.85, rgba(131, 182, 202, 0.2))),
				-webkit-gradient(linear, 0% 0%, 0% 100%, from(#e2f4fb), to(#91bfd1), color-stop(.5, #b5d4e0), color-stop(.5, #b5d4e0));
	-moz-box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.2);
	-webkit-box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.2);
	box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.2);
}
button#css3-button:hover{
	color:#01678F;
	background: -moz-linear-gradient(left, rgba(131, 182, 202,  0.8), rgba(131, 182, 202, 0.2) 15%, rgba(131, 182, 202, 0) 50%, rgba(131, 182, 202, 0.2) 85%, rgba(131, 182, 202, 0.8)),
				-moz-linear-gradient(top, #f7f7f7, #e2f4fb 50%, #e2f4fb 50%, #91bfd1);
	background: -webkit-gradient(linear, 0% 0%, 100% 0%, from(rgba(131, 182, 202, 0.8)), to(rgba(131, 182, 202, 0.8)), color-stop(.15, rgba(131, 182, 202, 0.2)), color-stop(.5, rgba(131, 182, 202, 0)), color-stop(.85, rgba(131, 182, 202, 0.2))),
				-webkit-gradient(linear, 0% 0%, 0% 100%, from(#f7f7f7), to(#91bfd1), color-stop(.5, #e2f4fb), color-stop(.5, #e2f4fb));
}
button#css3-button:active{
	color:#6EAAC2;
	border-color: #999999 #f1f1f1 #f1f1f1 #aaaaaa;
	background: -moz-linear-gradient(top, #f1f1f1, #dddddd);
	background: -webkit-gradient(linear, left top, left bottom, from(#f1f1f1), to(#dddddd));
}</p>
</style>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&nbsp;
&nbsp;
&lt;button id=&quot;css3-button&quot; type=&quot;button&quot;&gt;Cool Arse Button&lt;/button&gt;
&nbsp;
&nbsp;
&lt;style&gt;
button#css3-button{
	padding: 0.4em 1em 0.4em 1em;
	font-family:Helvetica, Arial, sans-serif;
	font-size:1.1em;
	color: #2885ab;
	letter-spacing:-0.05em;
	text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.4), 0px 0px 6px rgba(0, 0, 0, 0.2);
	font-weight:bold;
	cursor:pointer;
	border:1px solid #FFFFFF;
	-moz-border-radius: 0.7em;
	-webkit-border-radius: 0.7em;
	border-radius: 0.7em;
	background: -moz-linear-gradient(left, rgba(131, 182, 202,  0.8), rgba(131, 182, 202, 0.2) 15%, rgba(131, 182, 202, 0) 50%, rgba(131, 182, 202, 0.2) 85%, rgba(131, 182, 202, 0.8)),
				-moz-linear-gradient(top, #e2f4fb, #b5d4e0 50%, #b5d4e0 50%, #91bfd1);
	background: -webkit-gradient(linear, 0% 0%, 100% 0%, from(rgba(131, 182, 202, 0.8)), to(rgba(131, 182, 202, 0.8)), color-stop(.15, rgba(131, 182, 202, 0.2)), color-stop(.5, rgba(131, 182, 202, 0)), color-stop(.85, rgba(131, 182, 202, 0.2))),
				-webkit-gradient(linear, 0% 0%, 0% 100%, from(#e2f4fb), to(#91bfd1), color-stop(.5, #b5d4e0), color-stop(.5, #b5d4e0));
	-moz-box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.2);
	-webkit-box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.2);
	box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.2);
}
&nbsp;
button#css3-button:hover{
	color:#01678F;
	background: -moz-linear-gradient(left, rgba(131, 182, 202,  0.8), rgba(131, 182, 202, 0.2) 15%, rgba(131, 182, 202, 0) 50%, rgba(131, 182, 202, 0.2) 85%, rgba(131, 182, 202, 0.8)),
				-moz-linear-gradient(top, #f7f7f7, #e2f4fb 50%, #e2f4fb 50%, #91bfd1);
	background: -webkit-gradient(linear, 0% 0%, 100% 0%, from(rgba(131, 182, 202, 0.8)), to(rgba(131, 182, 202, 0.8)), color-stop(.15, rgba(131, 182, 202, 0.2)), color-stop(.5, rgba(131, 182, 202, 0)), color-stop(.85, rgba(131, 182, 202, 0.2))),
				-webkit-gradient(linear, 0% 0%, 0% 100%, from(#f7f7f7), to(#91bfd1), color-stop(.5, #e2f4fb), color-stop(.5, #e2f4fb));
}
&nbsp;
button#css3-button:active{
	color:#6EAAC2;
	border-color: #999999 #f1f1f1 #f1f1f1 #aaaaaa;
	background: -moz-linear-gradient(top, #f1f1f1, #dddddd);
	background: -webkit-gradient(linear, left top, left bottom, from(#f1f1f1), to(#dddddd));
}
&nbsp;
&lt;/style&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://jamesroberts.name/blog/2011/01/12/css3-dual-background-glow-highlight-button/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php imagick complex gradient composite image</title>
		<link>http://jamesroberts.name/blog/2010/06/20/php-imagick-complex-gradient-composite-image/</link>
		<comments>http://jamesroberts.name/blog/2010/06/20/php-imagick-complex-gradient-composite-image/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 20:57:27 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[imagick]]></category>
		<category><![CDATA[imagickDraw]]></category>
		<category><![CDATA[jpg]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[png]]></category>

		<guid isPermaLink="false">http://jamesroberts.name/blog/?p=133</guid>
		<description><![CDATA[Manipulating images with imagemagick for php can be difficult, especially when you are trying to create complex images for a web template. Here is a more complex example of how to create sweet dynamic web graphics. This is a version of a header image that I created for a template design. It involves 4 colors, [...]]]></description>
			<content:encoded><![CDATA[<p>Manipulating images with imagemagick for php can be difficult, especially when you are trying to create complex images for a web template.  Here is a more complex example of how to create sweet dynamic web graphics.  This is a version of a header image that I created for a template design.  It involves 4 colors, and adds a nice gradient sheen over the top of the base gradients.</p>
<p>The script first creates an new base image using the background color.  Next, the script uses imagickdraw to create some lines and solid rectangles.  Then the script creates another image which will fill in a gradient between the top two lines.  Now comes the more complicated part, adding the sheen over the image that was just created.</p>
<p>The hard part of this is the fact we need an almost horizontal gradient.  This involves creating two vertical gradients, reversing the color directions, then compositing them together.  Once they have been combined, we rotate the image just beyond vertical, then set the transparency to 50%.</p>
<p>Now, the script puts the gradient image and sheen image together, and you have a sweet looking header image&#8230;.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
&nbsp;
<span style="color: #000088;">$background</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;#FFFFFF&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$color1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#999999'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$color2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#333333'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$color3</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#CCCCCC'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//$cachefile = 'path/to/cachefile.jpg';</span>
<span style="color: #666666; font-style: italic;">//if (!file_exists($cachefile)) {</span>
&nbsp;
try<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Imagick<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$im</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">newImage</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">400</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">86</span><span style="color: #339933;">,</span> <span style="color: #000088;">$background</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;jpg&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$draw1</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ImagickDraw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$draw1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFillColor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$color1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$draw1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rectangle</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">400</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$draw1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFillColor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$color1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$draw1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rectangle</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">73</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">400</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">86</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$draw1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFillColor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$color1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$draw1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">line</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">400</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$draw1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFillColor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$color3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$draw1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">line</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">73</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">400</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">73</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$gradient1</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Imagick<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$gradient1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">newPseudoImage</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">400</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">70</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;gradient:&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$color1</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;-&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$color2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$im</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">compositeImage</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$gradient1</span><span style="color: #339933;">,</span> imagick<span style="color: #339933;">::</span><span style="color: #004000;">COMPOSITE_OVER</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$im</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">drawImage</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$draw1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #000088;">$gradient_over1</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Imagick<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$gradient_over1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">newPseudoImage</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">400</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;gradient:transparent-&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$background</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$gradient_over2</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Imagick<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$gradient_over2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">newPseudoImage</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">400</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;gradient:&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$background</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;-transparent&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$gradient_over</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Imagick<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$gradient_over</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">newImage</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">400</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">400</span><span style="color: #339933;">,</span><span style="color: #000088;">$color2</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$gradient_over</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">compositeImage</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$gradient_over1</span><span style="color: #339933;">,</span> imagick<span style="color: #339933;">::</span><span style="color: #004000;">COMPOSITE_OVER</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$gradient_over</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">compositeImage</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$gradient_over2</span><span style="color: #339933;">,</span> imagick<span style="color: #339933;">::</span><span style="color: #004000;">COMPOSITE_OVER</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">200</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$gradient_over</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rotateImage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'transparent'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">120</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$gradient_over</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setImageOpacity</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">.5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$im</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">compositeImage</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gradient_over</span><span style="color: #339933;">,</span> imagick<span style="color: #339933;">::</span><span style="color: #004000;">COMPOSITE_OVER</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">200</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
	<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Content-Type: image/jpg&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$im</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$im</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">writeImage</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cacheFilepath</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$im</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$im</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">destroy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Error: '</span><span style="color: #339933;">,</span>  <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
}else{
&nbsp;
	$canvas = new Imagick($cachefile);
	header(&quot;Content-Type: image/png&quot;);
	echo $canvas;
&nbsp;
}
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>As usual, I have commented out file caching code.  Simply uncomment those lines and put a correct cachefile path (directory must be writable by the server).</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesroberts.name/blog/2010/06/20/php-imagick-complex-gradient-composite-image/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>simple but useful php base object for mysql table interaction</title>
		<link>http://jamesroberts.name/blog/2010/06/20/simple-but-useful-php-base-object-for-mysql-table-interaction/</link>
		<comments>http://jamesroberts.name/blog/2010/06/20/simple-but-useful-php-base-object-for-mysql-table-interaction/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 20:05:11 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[extending objects]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[objects]]></category>

		<guid isPermaLink="false">http://jamesroberts.name/blog/?p=130</guid>
		<description><![CDATA[I started a project creating an online game which involved lots of objects and tables. Rather than rewrite the same code over and over, I decided to create a base object in which i could simple extend the base object to work with any mySQL table by simply listing all the fields. Here is the [...]]]></description>
			<content:encoded><![CDATA[<p>I started a project creating an online game which involved lots of objects and tables.  Rather than rewrite the same code over and over, I decided to create a base object in which i could simple extend the base object to work with any mySQL table by simply listing all the fields.</p>
<p>Here is the code for the base object:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
abstract <span style="color: #000000; font-weight: bold;">class</span> _base
<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$table</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$primary_field</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$primary_id</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$db_info</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'host'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'username'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'password'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'database'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">''</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$primary_id</span><span style="color: #339933;">=-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db_connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">primary_id</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">primary_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$primary_id</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">primary_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> load<span style="color: #009900;">&#40;</span><span style="color: #000088;">$primary_id</span><span style="color: #339933;">=-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$primary_id</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">primary_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$primary_id</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">primary_id</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">table</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; WHERE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">primary_field</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;='&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">primary_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' LIMIT 1&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errno</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;red b ac&quot;&gt;Query Fail ('</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #339933;">.</span><span style="color: #0000ff;">')&lt;br&gt;sql: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$sql</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">num_rows</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$tmp_vals</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">values</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tmp_vals</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp_vals</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$k</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$v</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> load_from_array<span style="color: #009900;">&#40;</span><span style="color: #000088;">$load_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$load_array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$field</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$field</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> save<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$primary_field</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">primary_field</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$save_new</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$primary_field</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$save_new</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare_save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$save_new</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">table</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;(&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span><span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">values</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;('&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;','&quot;</span><span style="color: #339933;">,</span><span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">values</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;')&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">.</span><span style="color: #000088;">$fields</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">' VALUES '</span><span style="color: #339933;">.</span><span style="color: #000088;">$values</span><span style="color: #339933;">;</span> 
&nbsp;
		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;UPDATE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">table</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; SET &quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$set</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">values</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$set</span><span style="color: #339933;">.=</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$set</span><span style="color: #009900;">&#41;</span>?<span style="color: #0000ff;">', '</span><span style="color: #339933;">:</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #000088;">$k</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$v</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$set</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; WHERE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$primary_field</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">primary_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errno</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;red b ac&quot;&gt;Query Fail ('</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #339933;">.</span><span style="color: #0000ff;">')&lt;br&gt;sql: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$sql</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$save_new</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$primary_field</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert_id</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> prepare_save<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">values</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">values</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">values</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">primary_field</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> set_or_get<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #000088;">$value</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_null</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_int</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$key</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> set<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #000088;">$value</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">is_null</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> get<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$key</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> object_info<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$object_info</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$object_info</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'primary_field'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">primary_field</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$object_info</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'table'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">table</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$object_info</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fields'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$object_info</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> db_connect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> mysqli<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db_info</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'host'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db_info</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db_info</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db_info</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'database'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>To extend the object to use a certain mysql table, you simply set the table name, list the name of the fields, and the primary key.  Then you ca access all the values of the mysql table with the variable name of the field names&#8230;. here is an example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> user <span style="color: #000000; font-weight: bold;">extends</span> _base
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$primary_field</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'user_id'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$table</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'users'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'user_id '</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'password'</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$user_id</span>  <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$username</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$password</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_id</span><span style="color: #339933;">=-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
&nbsp;
		parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_id</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$user_id</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> login<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT user_id FROM users WHERE username='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' AND password='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errno</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;red b ac&quot;&gt;Query Fail ('</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #339933;">.</span><span style="color: #0000ff;">')&lt;br&gt;sql: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$sql</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">num_rows</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$user_data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// do user login stuff</span>
&nbsp;
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://jamesroberts.name/blog/2010/06/20/simple-but-useful-php-base-object-for-mysql-table-interaction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

