<?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>Penguinsoft &#187; PHP</title>
	<atom:link href="http://penguinsoft.us/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://penguinsoft.us</link>
	<description>Application Development, Web Development, Innovative Software Solutions</description>
	<lastBuildDate>Mon, 23 Jan 2012 18:45:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MySQL Class for PHP</title>
		<link>http://penguinsoft.us/2010/08/mysql-class-for-php/</link>
		<comments>http://penguinsoft.us/2010/08/mysql-class-for-php/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 01:57:50 +0000</pubDate>
		<dc:creator>Tomi Lehto</dc:creator>
				<category><![CDATA[Code and Servers]]></category>
		<category><![CDATA[Awesomeness]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP/MySQL]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://penguinsoft.us/?p=553</guid>
		<description><![CDATA[This should get you started if you're looking to connect to MySQL database.]]></description>
			<content:encoded><![CDATA[<p>This should get you started if you&#8217;re looking to connect to MySQL database.<span id="more-553"></span></p>
<p>Requires a simple configuration file where you keep all your variables (user/password/etc, like SITEDB_HOSTNAME).</p>
<p>To connect, just drop these lines in the code</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mysqlClass.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> mysqlClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mystuff</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStuff</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>mysqlClass source:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> mysqlClass <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$_Link</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Construct: Open SQL</span>
	<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: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_Link <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span>SITEDB_HOSTNAME<span style="color: #339933;">,</span> SITEDB_USERNAME<span style="color: #339933;">,</span> SITEDB_PASSWORD<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SET NAMES 'utf8'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span>SITEDB_DATABASE<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: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_Link<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">callError</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Server connection error: &quot;</span> <span style="color: #339933;">.</span> SITEDB_HOSTNAME <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: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">callError</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Database open error: &quot;</span> <span style="color: #339933;">.</span> SITEDB_DATABASE <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>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Destruct: Close SQL</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __destruct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_Link<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Update sample</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> updateStuff<span style="color: #009900;">&#40;</span><span style="color: #000088;">$stuff</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</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: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;
			UPDATE 		stuff
			SET		stuff = '<span style="color: #009933; font-weight: bold;">%s</span>'
			WHERE		id = <span style="color: #009933; font-weight: bold;">%d</span>
		&quot;</span><span style="color: #339933;">,</span>
			<span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stuff</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_Link<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: #339933;">!</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">callError</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Update Error: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//Insert Sample</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> insertStuff<span style="color: #009900;">&#40;</span><span style="color: #000088;">$stuff</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: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;
			INSERT INTO		stuff
						(stuff)
				VALUES		('<span style="color: #009933; font-weight: bold;">%s</span>');
		&quot;</span><span style="color: #339933;">,</span>
			<span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stuff</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> or <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">callError</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Insert Error&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_insert_id</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Select Sample</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getStuff<span style="color: #009900;">&#40;</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: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;
                    SELECT          *
                    FROM            stuff
		&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_Link<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: #339933;">!</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">callError</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Result error: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$queryresult</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;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$queryresult</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #990000;">mysql_free_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$queryresult</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Show SQL errors</span>
	<span style="color: #000000; font-weight: bold;">function</span> callError<span style="color: #009900;">&#40;</span><span style="color: #000088;">$details</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;">echo</span> <span style="color: #0000ff;">'Database Error: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$details</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' Error: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://penguinsoft.us/2010/08/mysql-class-for-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Show Errors in PHP</title>
		<link>http://penguinsoft.us/2010/07/show-errors-in-php/</link>
		<comments>http://penguinsoft.us/2010/07/show-errors-in-php/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 03:39:57 +0000</pubDate>
		<dc:creator>Tomi Lehto</dc:creator>
				<category><![CDATA[Code and Servers]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://penguinsoft.us/?p=486</guid>
		<description><![CDATA[In the good &#8220;old&#8221; days when 99% of all websites looked horrible, PHP would by default spit out all errors. If you made a mistake in your code, you&#8217;d get gracefully &#8220;notified&#8221;. With PHP 5 we arrived to a new era of hidden rebukes &#8211; page just loads totally blank by default. If you like ...]]></description>
			<content:encoded><![CDATA[<p>In the good &#8220;old&#8221; days when 99% of all websites looked horrible, PHP would by default spit out all errors. If you made a mistake in your code, you&#8217;d get gracefully &#8220;notified&#8221;.</p>
<p>With PHP 5 we arrived to a new era of hidden rebukes &#8211; page just loads totally blank by default.</p>
<p>If you like games, you can just start searching the problem from your source code! If you have less than 100k lines you&#8217;ve got a good chance to find the issue before dawn.</p>
<p>If not, just drop these lines to the beginning of the script &#8211; should be fine&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'display_errors'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">error_reporting</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">E_ALL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://penguinsoft.us/2010/07/show-errors-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bible Module</title>
		<link>http://penguinsoft.us/2010/06/bible-module-for-thedesperate-com/</link>
		<comments>http://penguinsoft.us/2010/06/bible-module-for-thedesperate-com/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 13:44:00 +0000</pubDate>
		<dc:creator>Tomi Lehto</dc:creator>
				<category><![CDATA[Case Study]]></category>
		<category><![CDATA[Project Updates]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://penguinsoft.us/?p=337</guid>
		<description><![CDATA[Just finished a new module for TheD &#8211; Bible Module. This fancy feature allows visitors and users of TheDesperate.com to browse and search the King James Version (KJV) of the Bible. We&#8217;ve got some awesome added features planned, so this is just the beginning. Leave comments and let us know what you think: TheDesperate.com/bible]]></description>
			<content:encoded><![CDATA[<p>Just finished a new module for TheD &#8211; Bible Module. <span id="more-337"></span>This fancy feature allows visitors and users of TheDesperate.com to browse and search the King James Version (KJV) of the Bible. We&#8217;ve got some awesome added features planned, so this is just the beginning.</p>
<p>Leave comments and let us know what you think:</p>
<p><a href="http://TheDesperate.com/bible">TheDesperate.com/bible</a></p>
]]></content:encoded>
			<wfw:commentRss>http://penguinsoft.us/2010/06/bible-module-for-thedesperate-com/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Updates and Joins in MySQL</title>
		<link>http://penguinsoft.us/2010/03/updates-and-joins-in-mysql/</link>
		<comments>http://penguinsoft.us/2010/03/updates-and-joins-in-mysql/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 01:08:44 +0000</pubDate>
		<dc:creator>Tomi Lehto</dc:creator>
				<category><![CDATA[Code and Servers]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP/MySQL]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://penguinsoft.us/?p=183</guid>
		<description><![CDATA[Now this is supremely hot. You can update a whole set of information from one table to another without passing any data from your PHP. Not sure if this works with MS SQL, I&#8217;ll check next time I&#8217;m around those machines. Here is what I was after: Users on a website need the ability to ...]]></description>
			<content:encoded><![CDATA[<p>Now this is supremely hot. You can update a whole set of information from one table to another without passing any data from your PHP. Not sure if this works with MS SQL, I&#8217;ll check next time I&#8217;m around those machines.<span id="more-183"></span></p>
<p>Here is what I was after:</p>
<ol>
<li>Users on a website need the ability to customize their personal pages</li>
<li>We want to make it easy for them by using themes (pre-selected styles, fonts, colors)</li>
<li>Users must have the ability to adjust their theme if they so desire</li>
</ol>
<p>Here is what I did:</p>
<ol>
<li>Created a theme table to MySQL that includes all the fancy style columns, like font styles, colors, etc</li>
<li>Added columns to users page table to match those theme styles</li>
<li>I created a PHP function to apply a theme based on theme selected, and user&#8217;s id</li>
</ol>
<p>Awesomeness in this case comes to play when it&#8217;s time to change the theme. PHP is from a data object that has user id already set:</p>
<p>PHP Code:</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> setPageTheme<span style="color: #009900;">&#40;</span><span style="color: #000088;">$themeid</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: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;
        UPDATE userpages U
        INNER JOIN themes T ON T.themeid = <span style="color: #009933; font-weight: bold;">%d</span>
        SET U.background=T.background, U.font=T.font, U.textcolor=T.textcolor
        WHERE U.userid = <span style="color: #009933; font-weight: bold;">%d</span>
    &quot;</span><span style="color: #339933;">,</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">esc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$themeid</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;">userid</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_Link<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: #339933;">!</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">callError</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>So now you&#8217;ve got the theme transferred to users page, and then you just build a page where user can customize the theme further if they so desire. How cool is that? <img src='http://penguinsoft.us/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Hopefully this saves you some time.</p>
]]></content:encoded>
			<wfw:commentRss>http://penguinsoft.us/2010/03/updates-and-joins-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

