<?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>Leoganda.net &#187; PHP</title>
	<atom:link href="http://www.leoganda.net/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.leoganda.net</link>
	<description></description>
	<lastBuildDate>Tue, 25 May 2010 16:33:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Auto Post Using Javascript</title>
		<link>http://www.leoganda.net/auto-post-using-javascript/</link>
		<comments>http://www.leoganda.net/auto-post-using-javascript/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 12:37:05 +0000</pubDate>
		<dc:creator>leoganda</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.leoganda.net/?p=51</guid>
		<description><![CDATA[Hi there, a few weeks ago I was doing research about auto post from webpage to paypal payment page. The basic idea is the visitor fill the form, then when the visitor submit the form we will store visitor data input to database. Once data stored in database the page will be automatically redirected to [...]]]></description>
			<content:encoded><![CDATA[<p>Hi there, a few weeks ago I was doing research about auto post from webpage to paypal payment page. The basic idea is the visitor fill the form, then when the visitor submit the form we will store visitor data input to database. Once data stored in database the page will be automatically redirected to paypal website. It&#8217;s pretty easy, we will use JavaScript to do auto post. I wanna make this article as simple as possible, I just wanna show how to do auto post with Javascript.<span id="more-51"></span></p>
<h3>1. Database</h3>
<p>We will use simple database for this experiment, single table with 4 columns ( id, first_name, last_name, package).</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`javascriptpost`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`sales`</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">`id`</span> INT<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">6</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`first_name`</span> VARCHAR<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">30</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`last_name`</span> VARCHAR<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">30</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`package`</span> VARCHAR<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span>
<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">`id`</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE <span style="color: #66cc66;">=</span> MYISAM ;</pre></div></div>

<h3>2. Form (index.php)</h3>
<p>First we need a basic form for user to input, data will be posted to post.php.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
	&lt;body&gt;
		&lt;form action=&quot;post.php&quot; method=&quot;post&quot;&gt;						
				&lt;p&gt;
				&lt;label&gt;First Name&lt;/label&gt;
				&lt;input type=&quot;text&quot; id=&quot;first_name&quot; name=&quot;first_name&quot;/&gt;
				&lt;/p&gt;
				&lt;p&gt;
				&lt;label&gt;Last Name&lt;/label&gt;
				&lt;input type=&quot;text&quot; id=&quot;last_name&quot; name=&quot;last_name&quot;/&gt;
				&lt;/p&gt;				
				&lt;p&gt;
				&lt;label&gt;Package&lt;/label&gt;
				&lt;select id=&quot;package&quot; name=&quot;package&quot;&gt;
					&lt;option value=&quot;A&quot;&gt;A&lt;/option&gt;
					&lt;option value=&quot;B&quot;&gt;B&lt;/option&gt;
					&lt;option value=&quot;C&quot;&gt;C&lt;/option&gt;
				&lt;/select&gt;
				&lt;/p&gt;				
				&lt;input type=&quot;submit&quot; value=&quot;submit&quot;/&gt;				
		&lt;/form&gt;
	&lt;body&gt;
&lt;/html&gt;</pre></div></div>

<h3>3. Post.php</h3>
<p>In post.php we will retrieve the posted data from index.php and store the data to database.<br />
Once data stored, the pages will be redirected to paypal website.</p>
<p>We will use javascript syntax to do autopost,</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;JavaScript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">var</span> time <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span>
<span style="color: #003366; font-weight: bold;">function</span> subm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'paypal'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</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: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p><strong>post.php</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</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;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'first_name'</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: #000088;">$firstname</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'first_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$lastname</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'last_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$package</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'package'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$package</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;A&quot;</span><span style="color: #339933;">:</span> <span style="color: #000088;">$amount</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>break<span style="color: #339933;">;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;B&quot;</span><span style="color: #339933;">:</span> <span style="color: #000088;">$amount</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span>break<span style="color: #339933;">;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;C&quot;</span><span style="color: #339933;">:</span> <span style="color: #000088;">$amount</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">30</span><span style="color: #339933;">;</span>break<span style="color: #339933;">;</span>
		<span style="color: #b1b100;">default</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$amount</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO sales (first_name,last_name,package) values ('<span style="color: #006699; font-weight: bold;">$firstname</span>','<span style="color: #006699; font-weight: bold;">$lastname</span>','<span style="color: #006699; font-weight: bold;">$package</span>')&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$con</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;root&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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$con</span><span style="color: #009900;">&#41;</span>
	  <span style="color: #009900;">&#123;</span>
	  <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Could not connect: '</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  <span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;javascriptpost&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$con</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><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//insert to database</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Home&lt;/title&gt;
&nbsp;
&lt;script language=&quot;JavaScript&quot;&gt;
var time = null
function subm() {
document.getElementById('paypal').submit();
}
&lt;/script&gt;
&nbsp;
&lt;/head&gt;
	&lt;body  onload=&quot;timer=setTimeout('subm()',2500)&quot;&gt;
        &lt;div id=&quot;content&quot;&gt;
  			&lt;center&gt;
            	&lt;h3&gt;Thank you for booking&lt;/h3&gt;                
                &lt;p&gt;Now we will redirect to payment page&lt;/p&gt;            
            &lt;/center&gt;
				&lt;form action=&quot;https://www.paypal.com/cgi-bin/webscr&quot; method=&quot;post&quot; onSubmit=&quot;&quot; name=&quot;paypal&quot; id=&quot;paypal&quot;&gt;
					    &lt;input type=&quot;hidden&quot; name=&quot;cmd&quot; value=&quot;_xclick&quot;&gt;
						&lt;input type=&quot;hidden&quot; name=&quot;business&quot; value=&quot;your-email@email.com&quot;&gt;
						&lt;input type=&quot;hidden&quot; name=&quot;item_name&quot; value=&quot;Package <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$package</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
						&lt;input type=&quot;hidden&quot; name=&quot;amount&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$amount</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
						&lt;input type=&quot;hidden&quot; name=&quot;currency_code&quot; value=&quot;USD&quot;&gt;
						&lt;input type=&quot;hidden&quot; name=&quot;return&quot; value=&quot;http://www.leoganda.net&quot;&gt;
						&lt;input type=&quot;hidden&quot; name=&quot;defined_quantity&quot; value=&quot;1&quot;&gt;
				&lt;/form&gt;
			&lt;/div&gt;&lt;!--content--&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.leoganda.net/auto-post-using-javascript/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Solving Zend Framework error &#8220;An Error Has Occurred A project profile was not found&#8221;</title>
		<link>http://www.leoganda.net/solving-zend-framework-error-an-error-has-occurred-a-project-profile-was-not-found/</link>
		<comments>http://www.leoganda.net/solving-zend-framework-error-an-error-has-occurred-a-project-profile-was-not-found/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 02:39:22 +0000</pubDate>
		<dc:creator>leoganda</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Error]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.leoganda.net/?p=47</guid>
		<description><![CDATA[Hi there, I had an error &#8220;An Error Has Occurred A project profile was not found&#8221; on Zend framework command line when I tried to generate an action for my project. I&#8217;m using Windows XP and for the web server I&#8217;m using XAMPP. The &#8220;An Error Has Occurred A project profile was not found&#8221; happened [...]]]></description>
			<content:encoded><![CDATA[<p>Hi there, I had an error &#8220;<strong>An Error Has Occurred A project profile was not found</strong>&#8221; on Zend framework command line when I tried to generate an action for my project. I&#8217;m using Windows XP and for the web server I&#8217;m using XAMPP. The &#8220;<strong>An Error Has Occurred A project profile was not found</strong>&#8221; happened because we have wrong include path in our php.ini.</p>
<p>Open your php.ini and find the include_path line, insert your zend framework library path into the line before the PEAR path.</p>
<p><code>include_path = ".;E:\xampp\htdocs\ZendFramework\library;E:\xampp\php\PEAR"</code></p>
<p>Save the file and restart your Apache. Good luck <img src='http://www.leoganda.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.leoganda.net/solving-zend-framework-error-an-error-has-occurred-a-project-profile-was-not-found/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to enable XAMPP SSL socket transport</title>
		<link>http://www.leoganda.net/how-to-enable-xampp-ssl-socket-transport/</link>
		<comments>http://www.leoganda.net/how-to-enable-xampp-ssl-socket-transport/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 13:37:06 +0000</pubDate>
		<dc:creator>leoganda</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[XAMPP]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.leoganda.net/?p=24</guid>
		<description><![CDATA[Hi today I have an experiment with GData in Zend Framework PHP , and found an error that my XAMPP prevent SSL socket transport and return this error. Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Unable to Connect to ssl://www.google.com:443. Error #24: Unable to find the socket transport "ssl" - did you forget to enable [...]]]></description>
			<content:encoded><![CDATA[<p>Hi today I have an experiment with <a href="http://framework.zend.com/download/webservices" target="_blank">GData</a> in Zend Framework PHP , and found an error that my <a href="http://www.apachefriends.org/en/xampp.html" target="_blank">XAMPP </a>prevent SSL socket transport and return this error.</p>
<p><code>Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Unable to Connect to ssl://www.google.com:443. Error #24: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?'</code><span id="more-24"></span></p>
<p>Here&#8217;s the solution to make your XAMPP support socket transport SSL.<br />
1. First stop your Apache service<br />
2. Find <code>libeay32.dll</code> and <code>ssleay32.dll</code> in <code>xampp\php\</code> folder, and copy it into  <code>xampp\apache\bin\</code> folder. Just overwrite the older files in there.<br />
3. Edit <code>php.ini</code> file in <code>xampp\apache\bin</code>, remove the semicolon in &#8220;<code>;extension=php_openssl.dll</code>&#8221;<br />
4. Start the Apache service</p>
<p>That&#8217;s it, your SSL transport socket in your XAMPP has been activated.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leoganda.net/how-to-enable-xampp-ssl-socket-transport/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>How to connect MySQL in Prado Framework</title>
		<link>http://www.leoganda.net/how-to-connect-mysql-in-prado-framework/</link>
		<comments>http://www.leoganda.net/how-to-connect-mysql-in-prado-framework/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 16:00:55 +0000</pubDate>
		<dc:creator>leoganda</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Prado]]></category>

		<guid isPermaLink="false">http://www.leoganda.net/?p=8</guid>
		<description><![CDATA[Hello! This is my first article tutorial in this blog, today my friend have a problem connecting SQL databases with PRaDO framework. I have used this framework several years ago, and it&#8217;s quite easy to make a website with Prado. This time I will write how to connect MySQL with Prado, insert data, and display [...]]]></description>
			<content:encoded><![CDATA[<p>Hello!</p>
<p>This is my first article tutorial in this blog, today my friend have a problem connecting SQL databases with PRaDO framework. I have used this framework several years ago, and it&#8217;s quite easy to make a website with Prado. This time I will write how to connect MySQL with Prado, insert data, and display it in the web page.</p>
<p>First, I&#8217;m using XAMPPLITE as webserver, XAMPPLITE is lite version of XAMPP, but if you are using XAMPP it&#8217;s ok. <a title="Download XAMPP" href="http://www.apachefriends.org/en/xampp-windows.html" target="_blank">Download XAMPP</a>.</p>
<p>After you finish the XAMPP download, continue with download Prado framework. <a href="http://www.pradosoft.com/download/" target="_blank">Download Prado</a>.</p>
<p>Install the XAMPP, and extract the prado framework in htdocs folder.</p>
<p>The optional prado-cli.php PHP script file in the framework directory provides command line tools to perform various tedious takes in Prado. The prado-cli.php can be used to create Prado project skeletons, create initial test fixtures, and access to an interactive PHP shell. We will use command line tool to generate our prado project.<span id="more-8"></span></p>
<h3>1. Make setPath</h3>
<p>First I made setpath.bat to declare PHP path, so we can called any file in PHP path easier.</p>
<p>Make a file setpath.bat ( I put this file in C:\)</p>
<p><code>PATH=C:\xampplite\php\;</code></p>
<p>set the path to your php directory.</p>
<h3>2. Generate the Project</h3>
<p>Open the command prompt, and execute the setpath.bat by typing the filename setpath.bat</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/07/1-setpath.jpg"><img class="alignnone size-full wp-image-9" title="1 setpath" src="http://www.leoganda.net/wp-content/uploads/2009/07/1-setpath.jpg" alt="1 setpath" width="668" height="333" /></a></p>
<p>Go to htdocs</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/07/2-htdocs.jpg"><img class="alignnone size-full wp-image-10" title="2 htdocs" src="http://www.leoganda.net/wp-content/uploads/2009/07/2-htdocs.jpg" alt="2 htdocs" width="668" height="333" /></a></p>
<p>Let&#8217;s generate project, execute this line</p>
<p><code>php C:\xampplite\htdocs\prado\framework\prado-cli.php -c pradocontact</code></p>
<p>When the generate success the command line will display line like this</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/07/3-generate-project.jpg"><img class="alignnone size-full wp-image-11" title="3 generate project" src="http://www.leoganda.net/wp-content/uploads/2009/07/3-generate-project.jpg" alt="3 generate project" width="668" height="333" /></a></p>
<h3>3. Open in browser</h3>
<p>Open your browser and navigate to http://localhost/pradocontact/ if you see the prado welcome page, congratulations you have been generate prado project successly.</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/07/4-welcome-to-prado.jpg"><img class="alignnone size-full wp-image-12" title="4 welcome to prado" src="http://www.leoganda.net/wp-content/uploads/2009/07/4-welcome-to-prado.jpg" alt="4 welcome to prado" width="516" height="228" /></a></p>
<h3>4. Create Database</h3>
<p>Navigate to http://localhost/phpmyadmin/ and create new database. Type &#8220;pradocontact&#8221; in create new database field and hit create button.<br />
<a href="http://www.leoganda.net/wp-content/uploads/2009/07/5-create-database.jpg"><img src="http://www.leoganda.net/wp-content/uploads/2009/07/5-create-database.jpg" alt="5 create database" title="5 create database" width="578" height="260" class="alignnone size-full wp-image-13" /></a><br />
Then make a new table called &#8220;contact&#8221; with 2 field (id and name). Set the id field type into tinyint, auto_increment, and as primary key. Set the field name type as varchar and give the length 100.<br />
<a href="http://www.leoganda.net/wp-content/uploads/2009/07/6-create-table.jpg"><img src="http://www.leoganda.net/wp-content/uploads/2009/07/6-create-table.jpg" alt="6 create table" title="6 create table" width="439" height="122" class="alignnone size-full wp-image-14" /></a><br />
<a href="http://www.leoganda.net/wp-content/uploads/2009/07/7-field-table.jpg"><img src="http://www.leoganda.net/wp-content/uploads/2009/07/7-field-table.jpg" alt="7 field table" title="7 field table" width="554" height="104" class="alignnone size-full wp-image-15" /></a></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`contact`</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">`id`</span> TINYINT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`name`</span> VARCHAR<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">100</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
<span style="color: #66cc66;">&#41;</span> ENGINE <span style="color: #66cc66;">=</span> MYISAM ;
&nbsp;
After the <span style="color: #993333; font-weight: bold;">TABLE</span> created<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #cc66cc;">2</span> rows <span style="color: #993333; font-weight: bold;">DATA</span> <span style="color: #993333; font-weight: bold;">INTO</span> contact <span style="color: #993333; font-weight: bold;">TABLE</span><span style="color: #66cc66;">.</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`contact`</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">`id`</span> <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`name`</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">'1'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'leo'</span>
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">'2'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'ganda'</span>
<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<h3>5. Set connection in application.xml</h3>
<p>Browse your project folder and open the protected folder C:\xampplite\htdocs\pradocontact\protected</p>
<p>You will see a file &#8220;application.xml&#8221;, open it and edit.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;db&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;System.Data.TDataSourceConfig&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;database</span> <span style="color: #000066;">ConnectionString</span>=<span style="color: #ff0000;">&quot;mysql:host=localhost;dbname=pradocontact&quot;</span> <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;root&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;System.Data.ActiveRecord.TActiveRecordConfig&quot;</span> <span style="color: #000066;">ConnectionID</span>=<span style="color: #ff0000;">&quot;db&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>We make a <strong>ConnectionString </strong>to mysql database, dbname is our database that used for this project. Set the <strong>username </strong>and <strong>password </strong>with your database account.</p>
<h3>6. Create Active Record</h3>
<p>To use active record, I will make a new folder called database inside the protected folder to store the <strong>ActiveRecord </strong>file. After the database folder created, open the <code>application.xml</code> once again, and declare the database path.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;paths<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;using</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;Application.database.*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/paths<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Your <code>application.xml</code> should be look like this</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;application</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;pradocontact&quot;</span> <span style="color: #000066;">mode</span>=<span style="color: #ff0000;">&quot;Debug&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;paths<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;using</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;Application.database.*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/paths<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- configurations for modules --&gt;</span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;db&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;System.Data.TDataSourceConfig&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;database</span> <span style="color: #000066;">ConnectionString</span>=<span style="color: #ff0000;">&quot;mysql:host=localhost;dbname=pradocontact&quot;</span> <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;root&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;System.Data.ActiveRecord.TActiveRecordConfig&quot;</span> <span style="color: #000066;">ConnectionID</span>=<span style="color: #ff0000;">&quot;db&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- configuration for available services --&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;services<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;page&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;TPageService&quot;</span> <span style="color: #000066;">DefaultPage</span>=<span style="color: #ff0000;">&quot;Home&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/services<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- application parameters</span>
<span style="color: #808080; font-style: italic;">  &lt;parameters&gt;</span>
<span style="color: #808080; font-style: italic;">    &lt;parameter id=&quot;param1&quot; value=&quot;value1&quot; /&gt;</span>
<span style="color: #808080; font-style: italic;">    &lt;parameter id=&quot;param2&quot; value=&quot;value2&quot; /&gt;</span>
<span style="color: #808080; font-style: italic;">  &lt;/parameters&gt;</span>
<span style="color: #808080; font-style: italic;">  --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>After you finish editing the <code>application.xml</code>, let&#8217;s generate Active Record from our database in MySQL.<br />
Open the command prompt again, go to C:\xampplite\htdocs\pradocontact\ and execute <code>php C:\xampplite\htdocs\prado\framework\prado-cli.php shell .</code></p>
<p>execute <code>generate contact Application.database.ContactRecord</code></p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/07/8-generate-AR.jpg"><img src="http://www.leoganda.net/wp-content/uploads/2009/07/8-generate-AR.jpg" alt="8 generate AR" title="8 generate AR" width="668" height="333" class="alignnone size-full wp-image-16" /></a></p>
<p>Open your database folder with explorer, and you will find a new file called ContactRecord.php, try to open it.</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>
<span style="color: #009933; font-style: italic;">/**
 * Auto generated by prado-cli.php on 2009-07-18 03:01:37.
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> ContactRecord <span style="color: #000000; font-weight: bold;">extends</span> TActiveRecord
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">const</span> TABLE<span style="color: #339933;">=</span><span style="color: #0000ff;">'contact'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$name</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> finder<span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">finder</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</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: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>7. Test The Active Record</h3>
<p>Ok, let test our Active Record using command line tools, type &#8220;ContactRecord::finder()-&gt;findAll()&#8221; and hit enter. See the image below.<br />
<a href="http://www.leoganda.net/wp-content/uploads/2009/07/9-test-AR.jpg"><img src="http://www.leoganda.net/wp-content/uploads/2009/07/9-test-AR.jpg" alt="9 test AR" title="9 test AR" width="668" height="333" class="alignnone size-full wp-image-17" /></a><br />
The command line return an array with 2 record from the mySQL database and that means our activeRecord running well!</p>
<h3>8. Edit Home.page</h3>
<p>paste this code on your Home.page file<br />
<code><br />
&lt;%@ Title="Contact List" %&gt;</p>
<p>&lt;h1&gt;Contact List&lt;/h1&gt;</p>
<p>&lt;a href="&lt;%= $this-&gt;Service-&gt;constructUrl('insert')%&gt;"&gt;Create New Contact&lt;/a&gt;<br />
&lt;br/&gt;</p>
<p>&lt;com:TDataGrid ID="UserGrid"<br />
DataKeyField="id"<br />
AutoGenerateColumns="false"<br />
&gt;</p>
<p>&lt;com:TBoundColumn<br />
HeaderText="ID"<br />
DataField="id" /&gt;</p>
<p>&lt;com:TBoundColumn<br />
HeaderText="Name"<br />
DataField="name" /&gt;</p>
<p>&lt;/com:TDataGrid&gt;<br />
</code></p>
<h3>9. Make new file Home.php</h3>
<p>Paste this code on your Home.php</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>
<span style="color: #000000; font-weight: bold;">class</span> Home <span style="color: #000000; font-weight: bold;">extends</span> TPage
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * Populates the datagrid with user lists.
     * This method is invoked by the framework when initializing the page
     * @param mixed event parameter
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> onInit<span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span><span style="color: #004000;">onInit</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// fetches all data account information</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">UserGrid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DataSource</span><span style="color: #339933;">=</span>ContactRecord<span style="color: #339933;">::</span><span style="color: #004000;">finder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// binds the data to interface components</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">UserGrid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dataBind</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>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>10. Make a new file insert.page</h3>
<p><code><br />
&lt;%@ Title="Insert Contact" %&gt;</p>
<p>&lt;com:TForm&gt;</p>
<p>&lt;h1&gt;Insert Contact&lt;/h1&gt;</p>
<p>&lt;span&gt;Name:&lt;/span&gt;<br />
&lt;br/&gt;<br />
&lt;com:TTextBox ID="Name" /&gt;</p>
<p>&lt;com:TButton Text="Create" OnClick="createButtonClicked" /&gt;</p>
<p>&lt;/com:TForm&gt;<br />
</code></p>
<h3>11. Make a new file insert.php</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> insert <span style="color: #000000; font-weight: bold;">extends</span> TPage
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> createButtonClicked<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sender</span><span style="color: #339933;">,</span><span style="color: #000088;">$param</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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">IsValid</span><span style="color: #009900;">&#41;</span>  <span style="color: #666666; font-style: italic;">// when all validations succeed</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// populates a UserRecord object with user inputs</span>
            <span style="color: #000088;">$ContactRecord</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> ContactRecord<span style="color: #339933;">;</span>
            <span style="color: #000088;">$ContactRecord</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Name</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Text</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
            <span style="color: #666666; font-style: italic;">// saves to the database via Active Record mechanism</span>
            <span style="color: #000088;">$ContactRecord</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// redirects the browser to the homepage</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Service</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DefaultPageUrl</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>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><a href="http://www.leoganda.net/wp-content/uploads/2009/07/10-file-structure.jpg"><img src="http://www.leoganda.net/wp-content/uploads/2009/07/10-file-structure.jpg" alt="10 file structure" title="10 file structure" width="497" height="337" class="alignnone size-full wp-image-18" /></a></p>
<p>Navigate your browser to <code>http://localhost/pradocontact/ </code>you will see this page<br />
<a href="http://www.leoganda.net/wp-content/uploads/2009/07/11-final.jpg"><img src="http://www.leoganda.net/wp-content/uploads/2009/07/11-final.jpg" alt="11 final" title="11 final" width="506" height="311" class="alignnone size-full wp-image-19" /></a></p>
<p>Ok, thanks for reading. Have a nice day! <img src='http://www.leoganda.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://www.leoganda.net/source/pradocontact.rar">Download Source</a><br />
<a href="http://www.leoganda.net/source/pradocontact.sql">Download SQL</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.leoganda.net/how-to-connect-mysql-in-prado-framework/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
