<?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>Wild Web Works Blogs &#187; PHP</title>
	<atom:link href="http://www.wildwebworks.com/blogs/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wildwebworks.com/blogs</link>
	<description>Programming</description>
	<lastBuildDate>Wed, 15 Apr 2009 21:41:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using Value Objects in Postgres and Flex</title>
		<link>http://www.wildwebworks.com/blogs/2009/04/using-value-objects-in-postgres-and-flex/</link>
		<comments>http://www.wildwebworks.com/blogs/2009/04/using-value-objects-in-postgres-and-flex/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 14:43:34 +0000</pubDate>
		<dc:creator>spidee</dc:creator>
				<category><![CDATA[Adobe Flex - Actionscript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Pgsql]]></category>
		<category><![CDATA[Postgres Php]]></category>
		<category><![CDATA[Vo]]></category>
		<category><![CDATA[zend AMF]]></category>

		<guid isPermaLink="false">http://www.wildwebworks.com/blogs/?p=42</guid>
		<description><![CDATA[Using VO records with the Postgres/PHP/Flex trio is the way to go.  It guarantees that your objects come over in the correct format in direct correlation to what you have going on in all three programs.  ZendAMF really likes VOs, too.

There is one HUGE THING TO REMEMBER IN FLEX &#8211; You must instantiate [...]]]></description>
			<content:encoded><![CDATA[<p>Using VO records with the Postgres/PHP/Flex trio is the way to go.  It guarantees that your objects come over in the correct format in direct correlation to what you have going on in all three programs.  ZendAMF really likes VOs, too.</p>
<p><span id="more-42"></span></p>
<p>There is one HUGE THING TO REMEMBER IN FLEX &#8211; You must instantiate a VO to use it or refer to it on the page.  Sometimes you&#8217;ll have to just create a new instance that never goes anywhere or does anything.  Otherwise you&#8217;ll have problems that are really hard to understand.</p>
<p>Here&#8217;s a VO class in ActionScript</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package valueObjects
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> utility.<span style="color: #006600;">AMFDateConverter</span>;
	<span style="color: #0066CC;">import</span> utility.<span style="color: #006600;">BooleanConverter</span>;
	<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#91;</span>RemoteClass<span style="color: #66cc66;">&#40;</span>alias=<span style="color: #ff0000;">&quot;valueObjects.GLTransVO&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GLTransVO
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> gl_trans_id:uint;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _trans_date:<span style="color: #0066CC;">Date</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> trans_amt:<span style="color: #0066CC;">Number</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> trans_note:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _trans_void:<span style="color: #0066CC;">Boolean</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> trans_desc:uint;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> trans_num:uint;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> trans_id:uint;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> gl_id:uint;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> ref_id:uint;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> applied_amt:<span style="color: #0066CC;">Number</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> bal_amt:<span style="color: #0066CC;">Number</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> dr_amt:<span style="color: #0066CC;">Number</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> cr_amt:<span style="color: #0066CC;">Number</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> detail_amt:<span style="color: #0066CC;">Number</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> ledger_bal:<span style="color: #0066CC;">Number</span>;
&nbsp;
 		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> trans_date<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Date</span>
 		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _trans_date;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> trans_date<span style="color: #66cc66;">&#40;</span>value:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>value is <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				_trans_date = AMFDateConverter.<span style="color: #006600;">convert</span><span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #66cc66;">&#123;</span>
				_trans_date = value as <span style="color: #0066CC;">Date</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> trans_void<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _trans_void;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> trans_void<span style="color: #66cc66;">&#40;</span>value:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_trans_void = BooleanConverter.<span style="color: #006600;">convertBool</span><span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>I chose this VO because it has both the boolean and date converter on it that we&#8217;ve provided in prior blogs.  Also, it has special calculated fields that don&#8217;t get saved in Postgres.  They do get passed in and Postgres uses the data in pl/pgsql functions.</p>
<p>This is one important feature of using VO records.  You have to anticipate what you might need to save or pass through the life of the record from Postgres to PHP to Flex and back again.  Rarely will your VO actually match the fields of any single table.  You could have table joins and data manipulation in Postgres to get that final VO record.  As long as you&#8217;re consistent, this works very well.</p>
<p>Here&#8217;s the PHP VO -</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: #000000; font-weight: bold;">class</span> GLTransVO<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$gl_trans_id</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$trans_date</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$trans_amt</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$trans_note</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$trans_void</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$trans_desc</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$trans_num</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$trans_id</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$gl_id</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$ref_id</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$applied_amt</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$bal_amt</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$dr_amt</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$cr_amt</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$detail_amt</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$ledger_bal</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This is very easy to build in PHP.  Just make sure it matches!</p>
<p>We actually build Types in Postgres that correspond to the VO.  It&#8217;s yet another way to make sure that data types stay true throughout the process.  It also REALLY, REALLY cuts down on the code to call a pl/pgsql function.  Normally you have to specify each field of the return record.  If you use Types, you just specify the type.</p>
<p>Here&#8217;s the code to create a Postgres Type -</p>

<div class="wp_syntax"><div class="code"><pre class="plsql" style="font-family:monospace;"><span style="color: #00F;">CREATE</span> <span style="color: #00F;">TYPE</span> gl_trans_vo <span style="color: #00F;">AS</span>
   <span style="color: #00F;">&#40;</span>gl_trans_id <span style="color: #00F;">INTEGER</span><span style="color: #00F;">,</span>
    trans_date <span style="color: #00F;">TIMESTAMP</span> without <span style="color: #00F;">TIME</span> <span style="color: #00F;">ZONE</span><span style="color: #00F;">,</span>
    trans_amt numeric<span style="color: #00F;">&#40;</span><span style="color: #800;">10</span><span style="color: #00F;">,</span><span style="color: #800;">2</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>
    trans_note text<span style="color: #00F;">,</span>
    trans_void <span style="color: #00F;">BOOLEAN</span><span style="color: #00F;">,</span>
    trans_desc <span style="color: #00F;">INTEGER</span><span style="color: #00F;">,</span>
    trans_num <span style="color: #00F;">INTEGER</span><span style="color: #00F;">,</span>
    trans_id <span style="color: #00F;">INTEGER</span><span style="color: #00F;">,</span>
    gl_id <span style="color: #00F;">INTEGER</span><span style="color: #00F;">,</span>
    ref_id <span style="color: #00F;">INTEGER</span><span style="color: #00F;">,</span>
    applied_amt numeric<span style="color: #00F;">&#40;</span><span style="color: #800;">10</span><span style="color: #00F;">,</span><span style="color: #800;">2</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>
    bal_amt numeric<span style="color: #00F;">&#40;</span><span style="color: #800;">10</span><span style="color: #00F;">,</span><span style="color: #800;">2</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>
    dr_amt numeric<span style="color: #00F;">&#40;</span><span style="color: #800;">10</span><span style="color: #00F;">,</span><span style="color: #800;">2</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>
    cr_amt numeric<span style="color: #00F;">&#40;</span><span style="color: #800;">10</span><span style="color: #00F;">,</span><span style="color: #800;">2</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>
    detail_amt numeric<span style="color: #00F;">&#40;</span><span style="color: #800;">10</span><span style="color: #00F;">,</span><span style="color: #800;">2</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>
    ledger_bal numeric<span style="color: #00F;">&#40;</span><span style="color: #800;">10</span><span style="color: #00F;">,</span><span style="color: #800;">2</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span></pre></div></div>

<p>Here&#8217;s the beginning and the end of a Postgres function using the type.</p>

<div class="wp_syntax"><div class="code"><pre class="plsql" style="font-family:monospace;"><span style="color: #00F;">CREATE</span> <span style="color: #00F;">OR</span> <span style="color: #000;">REPLACE</span> <span style="color: #00F;">FUNCTION</span> gl_trans<span style="color: #00F;">&#40;</span>g_id <span style="color: #00F;">INTEGER</span><span style="color: #00F;">&#41;</span>
  RETURNS SETOF gl_trans_vo <span style="color: #00F;">AS</span>
$BODY$
<span style="color: #00F;">DECLARE</span>
gl_trans_list gl_trans_vo<span style="color: #00F;">;</span>
 <span style="color: #080; font-style: italic;">---------skipping code</span>
 <span style="color: #00F;">RETURN</span> NEXT gl_trans_list<span style="color: #00F;">;</span>
 <span style="color: #00F;">END</span> <span style="color: #00F;">LOOP</span><span style="color: #00F;">;</span>
<span style="color: #00F;">END</span><span style="color: #00F;">;</span>
$BODY$</pre></div></div>

<p>This is called from PHP and passed to Flex.  Here&#8217;s the code for PHP</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> getGLTrans<span style="color: #009900;">&#40;</span><span style="color: #000088;">$g_id</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$db</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 gl_trans(<span style="color: #006699; font-weight: bold;">$g_id</span>) ORDER BY trans_date&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<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: #b1b100;">return</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAllObjects</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GLTransVO'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>When you use debugging in Flex, you can actually see your VO with it&#8217;s proper name.  Here&#8217;s a screen shot of that -<br />
<img class="size-full wp-image-45 aligncenter" title="Using Value Objects" src="http://www.wildwebworks.com/blogs/wp-content/uploads/2009/04/4-13-2009-4-50-48-pm.png" alt="Using Value Objects" width="461" height="455" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wildwebworks.com/blogs/2009/04/using-value-objects-in-postgres-and-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Actionscript vs Postgres &#8211; Boolean Values</title>
		<link>http://www.wildwebworks.com/blogs/2009/04/actionscript-vs-postgres-boolean-values/</link>
		<comments>http://www.wildwebworks.com/blogs/2009/04/actionscript-vs-postgres-boolean-values/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 23:27:59 +0000</pubDate>
		<dc:creator>spidee</dc:creator>
				<category><![CDATA[Adobe Flex - Actionscript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Boolean Values]]></category>
		<category><![CDATA[zend AMF]]></category>

		<guid isPermaLink="false">http://www.wildwebworks.com/blogs/?p=31</guid>
		<description><![CDATA[Actionscript does not send boolean values that Postgres can take.  You need to work a little magic on the way over.

For VO records coming in from Postgres via PHP we use the following class.

package utility
&#123;
	public class BooleanConverter
	&#123;
		public static function convertBool&#40;pgBool:String&#41;:Boolean&#123;
			var newBool:Boolean = new Boolean;
			if&#40;pgBool == &#34;t&#34; &#124;&#124; pgBool == &#34;T&#34; &#124;&#124; pgBool == &#34;1&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>Actionscript does not send boolean values that Postgres can take.  You need to work a little magic on the way over.</p>
<p><span id="more-31"></span></p>
<p>For VO records coming in from Postgres via PHP we use the following class.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package utility
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BooleanConverter
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> convertBool<span style="color: #66cc66;">&#40;</span>pgBool:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> newBool:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Boolean</span>;
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>pgBool == <span style="color: #ff0000;">&quot;t&quot;</span> <span style="color: #66cc66;">||</span> pgBool == <span style="color: #ff0000;">&quot;T&quot;</span> <span style="color: #66cc66;">||</span> pgBool == <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #66cc66;">||</span> pgBool == <span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				newBool = <span style="color: #000000; font-weight: bold;">true</span>;
			<span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #66cc66;">&#123;</span>
				newBool = <span style="color: #000000; font-weight: bold;">false</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #b1b100;">return</span> newBool;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Then we use getter/setter on the VO calling the class.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">	<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#91;</span>RemoteClass<span style="color: #66cc66;">&#40;</span>alias=<span style="color: #ff0000;">&quot;valueObjects.OwnerVO&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> OwnerVO
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> pk_id:uint;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> owner_company:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _owner_active:<span style="color: #0066CC;">Boolean</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> owner_active<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _owner_active;
		<span style="color: #66cc66;">&#125;</span> 
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> owner_active<span style="color: #66cc66;">&#40;</span>value:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_owner_active = BooleanConverter.<span style="color: #006600;">convertBool</span><span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>You have to convert the other direction, too.  Saving from Actionscript to Postgres requires PHP to step in and perform some magic.  Here&#8217;s the PHP function, which we have on &#8216;conversions.php&#8217;.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">function</span> boolConversion<span style="color: #66cc66;">&#40;</span>$input<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span>$input<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'t'</span>:
				$output = <span style="color: #cc66cc;">1</span>;
				<span style="color: #b1b100;">break</span>;
			<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'1'</span>:
				$output = <span style="color: #cc66cc;">1</span>;
				<span style="color: #b1b100;">break</span>;
			<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'f'</span>:
				$output = <span style="color: #cc66cc;">0</span>;
				<span style="color: #b1b100;">break</span>;
			<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">''</span>:
				$output = <span style="color: #cc66cc;">0</span>;
				<span style="color: #b1b100;">break</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #b1b100;">return</span> $output;
	<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Here&#8217;s the PHP page receiving the VO from Flex and sending it over to Postgres.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">require_once<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;conversions.php&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Owners
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> saveOwner<span style="color: #66cc66;">&#40;</span>$record<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		global $db;
&nbsp;
		$record-<span style="color: #66cc66;">&gt;</span>owner_active = boolConversion<span style="color: #66cc66;">&#40;</span>$record-<span style="color: #66cc66;">&gt;</span>owner_active<span style="color: #66cc66;">&#41;</span>;
&nbsp;
		$sql = <span style="color: #ff0000;">&quot;SELECT * FROM owner_save((
		'$record-&gt;pk_id',
		'$record-&gt;owner_company',
		'$record-&gt;owner_active'))&quot;</span>;
&nbsp;
		$db-<span style="color: #66cc66;">&gt;</span>query<span style="color: #66cc66;">&#40;</span>$sql<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">return</span> $db-<span style="color: #66cc66;">&gt;</span>fetchObject<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'OwnerVO'</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Once this is set up, it works really well.  Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wildwebworks.com/blogs/2009/04/actionscript-vs-postgres-boolean-values/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Database Connection Class &#8211; Flex,PHP,Postgres</title>
		<link>http://www.wildwebworks.com/blogs/2009/04/database-connection-class-flexphppostgres/</link>
		<comments>http://www.wildwebworks.com/blogs/2009/04/database-connection-class-flexphppostgres/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 18:02:50 +0000</pubDate>
		<dc:creator>spidee</dc:creator>
				<category><![CDATA[Adobe Flex - Actionscript]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Database Connection]]></category>
		<category><![CDATA[flex database connection]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[zend AMF]]></category>

		<guid isPermaLink="false">http://www.wildwebworks.com/blogs/?p=26</guid>
		<description><![CDATA[We reuse our database connection many times throughout our code.  The call is a bit complex and continually copying it was a waste of space.  We came up with a class.  This is the DBConnection.as page in its entirety.


package utility
&#123;
	// Import
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;
&#160;
	public class DBConnection
	&#123;
	// Create Remote Object for connection to PHP [...]]]></description>
			<content:encoded><![CDATA[<p>We reuse our database connection many times throughout our code.  The call is a bit complex and continually copying it was a waste of space.  We came up with a class.  This is the DBConnection.as page in its entirety.</p>
<p><span id="more-26"></span></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package utility
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">// Import</span>
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #006600;">Alert</span>;
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">FaultEvent</span>;
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">ResultEvent</span>;
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">remoting</span>.<span style="color: #006600;">RemoteObject</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DBConnection
	<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">// Create Remote Object for connection to PHP then Postgres for records ArrayCollection</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> dbConnect:RemoteObject = <span style="color: #000000; font-weight: bold;">new</span> RemoteObject;
&nbsp;
<span style="color: #808080; font-style: italic;">// Data</span>
	<span style="color: #808080; font-style: italic;">//pass in parameters for specific record array request with or without </span>
	<span style="color: #808080; font-style: italic;">//array of parameters to include in function call to PHP</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> loadRecords<span style="color: #66cc66;">&#40;</span>dest:<span style="color: #0066CC;">String</span>, srce:<span style="color: #0066CC;">String</span>, phpCall:<span style="color: #0066CC;">String</span>, resultFunc:<span style="color: #000000; font-weight: bold;">Function</span>, args:<span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
		dbConnect.<span style="color: #006600;">destination</span> = dest;
		dbConnect.<span style="color: #006600;">source</span> = srce;
		dbConnect.<span style="color: #006600;">getOperation</span><span style="color: #66cc66;">&#40;</span>phpCall<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ResultEvent.<span style="color: #006600;">RESULT</span>, resultFunc<span style="color: #66cc66;">&#41;</span>;
		dbConnect.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>FaultEvent.<span style="color: #006600;">FAULT</span>, faultHandler<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>args.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		 dbConnect.<span style="color: #006600;">getOperation</span><span style="color: #66cc66;">&#40;</span>phpCall<span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">arguments</span> = args;
		<span style="color: #66cc66;">&#125;</span>
		dbConnect.<span style="color: #006600;">getOperation</span><span style="color: #66cc66;">&#40;</span>phpCall<span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> faultHandler<span style="color: #66cc66;">&#40;</span>event:FaultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
			Alert.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">fault</span>.<span style="color: #006600;">faultString</span>, event.<span style="color: #006600;">fault</span>.<span style="color: #006600;">faultCode</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The call is then very simple every time you need it.  You can leave the array empty if you have no parameters to pass, or put them all in.  Here&#8217;s an example of each.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//Load Records - WITH PARAM &amp; VARIABLES	</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getPeopleByRef<span style="color: #66cc66;">&#40;</span>r_id:uint, r_short:<span style="color: #0066CC;">Boolean</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>	
		<span style="color: #000000; font-weight: bold;">var</span> dbConn:DBConnection = <span style="color: #000000; font-weight: bold;">new</span> DBConnection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		dbConn.<span style="color: #006600;">loadRecords</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;zend&quot;</span>,<span style="color: #ff0000;">&quot;People&quot;</span>,<span style="color: #ff0000;">&quot;getPeopleByRef&quot;</span>, resultGetPeople,<span style="color: #66cc66;">&#91;</span>r_id<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//Load Records - NO PARAMS	</span>
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getContracts<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> dbConn:DBConnection = <span style="color: #000000; font-weight: bold;">new</span> DBConnection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		dbConn.<span style="color: #006600;">loadRecords</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;zend&quot;</span>,<span style="color: #ff0000;">&quot;Contract&quot;</span>,<span style="color: #ff0000;">&quot;getContracts&quot;</span>,resultGetContracts,<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This works great every time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wildwebworks.com/blogs/2009/04/database-connection-class-flexphppostgres/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
