<?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; Zend</title>
	<atom:link href="http://www.wildwebworks.com/blogs/tag/zend/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>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>
