<?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; MySQL</title>
	<atom:link href="http://www.leoganda.net/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.leoganda.net</link>
	<description></description>
	<lastBuildDate>Fri, 09 Dec 2011 04:12:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>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" rel="lightbox[8]"><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" rel="lightbox[8]"><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" rel="lightbox[8]"><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" rel="lightbox[8]"><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" rel="lightbox[8]"><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" rel="lightbox[8]"><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" rel="lightbox[8]"><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> <span style="color: #993333; font-weight: bold;">VARCHAR</span><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> <span style="color: #993333; font-weight: bold;">ROWS</span> <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" rel="lightbox[8]"><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" rel="lightbox[8]"><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" rel="lightbox[8]"><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" rel="lightbox[8]"><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>
<h4>What people search:</h4><ul><li><a href="http://www.leoganda.net/how-to-connect-mysql-in-prado-framework/" title="prado mysql">prado mysql</a></li><li><a href="http://www.leoganda.net/how-to-connect-mysql-in-prado-framework/" title="prado framework tutorial">prado framework tutorial</a></li><li><a href="http://www.leoganda.net/how-to-connect-mysql-in-prado-framework/" title="prado framework">prado framework</a></li><li><a href="http://www.leoganda.net/how-to-connect-mysql-in-prado-framework/" title="tutorial prado framework">tutorial prado framework</a></li><li><a href="http://www.leoganda.net/how-to-connect-mysql-in-prado-framework/" title="framework prado">framework prado</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.leoganda.net/how-to-connect-mysql-in-prado-framework/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>

