<?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>Rochak Chauhan::Unpredictably Exciting &#187; PHP</title>
	<atom:link href="http://rochakchauhan.com/blog/category/tips-and-tricks/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://rochakchauhan.com/blog</link>
	<description>Know your limits, but never stop trying to exceed them.</description>
	<lastBuildDate>Thu, 03 May 2012 11:48:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>India will become Number 1 source of PHP developers soon</title>
		<link>http://rochakchauhan.com/blog/2009/07/30/india-will-become-number-1-source-of-php-developers-soon/</link>
		<comments>http://rochakchauhan.com/blog/2009/07/30/india-will-become-number-1-source-of-php-developers-soon/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 09:07:26 +0000</pubDate>
		<dc:creator>rochakchauhan</dc:creator>
				<category><![CDATA[General News]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[India PHP Developers Nunber 1]]></category>

		<guid isPermaLink="false">http://rochakchauhan.com/blog/?p=949</guid>
		<description><![CDATA[The number of Indian PHP developers has been growing at a large pace in the last few years, when compared to other countries. A few years ago, India was just one of the top ten countries with more PHP developers. Now India is number 2 and is almost surpassing United States, which is still number &#8230; <a class="read-excerpt" href="http://rochakchauhan.com/blog/2009/07/30/india-will-become-number-1-source-of-php-developers-soon/">Continue reading <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>The number of Indian PHP developers has been growing at a large pace in the last few years, when compared to other countries. A few years ago, India was just one of the top ten countries with more PHP developers. Now India is number 2 and is almost surpassing United States, which is still number 1.</p>
<p>This article presents a reflection about why this growth happened just in the latest years, as well what it means for the PHP world.</em></p>
<p><em><a title="India will become number 1 source of PHP developers soon" href="http://www.phpclasses.org/blog/post/99-India-will-become-number-1-source-of-PHP-developers-soon.html" target="_blank">Click here to read the full post&#8230;</a><br />
</em></p>
]]></content:encoded>
			<wfw:commentRss>http://rochakchauhan.com/blog/2009/07/30/india-will-become-number-1-source-of-php-developers-soon/feed/</wfw:commentRss>
		<slash:comments>498</slash:comments>
		</item>
		<item>
		<title>Top Ten Security Vulnerabilities in PHP Code !</title>
		<link>http://rochakchauhan.com/blog/2008/07/13/top-ten-security-vulnerabilities-in-php-code/</link>
		<comments>http://rochakchauhan.com/blog/2008/07/13/top-ten-security-vulnerabilities-in-php-code/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 08:29:57 +0000</pubDate>
		<dc:creator>rochakchauhan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Security Vulnerabilities]]></category>

		<guid isPermaLink="false">http://rochakchauhan.com/blog/2008/07/13/top-ten-security-vulnerabilities-in-php-code/</guid>
		<description><![CDATA[1. Unvalidated Parameters Most importantly, turn off register_globals. This configuration setting defaults to off in PHP 4.2.0 and later. Access values from URLs, forms, and cookies through the superglobal arrays $_GET, $_POST, and $_COOKIE. Before you use values from the superglobal arrays, validate them to make sure they don&#8217;t contain unexpected input. If you know &#8230; <a class="read-excerpt" href="http://rochakchauhan.com/blog/2008/07/13/top-ten-security-vulnerabilities-in-php-code/">Continue reading <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<h2><span class="byline"></span> 1. Unvalidated Parameters</h2>
<p>Most importantly, turn off <code>register_globals</code>. This configuration setting defaults to off in PHP 4.2.0 and later. Access values from URLs, forms, and cookies through the superglobal arrays <code>$_GET</code>, <code>$_POST</code>, and <code>$_COOKIE</code>.</p>
<p>Before you use values from the superglobal arrays, validate them to make sure they don&#8217;t contain unexpected input. If you know what type of value you are expecting, make sure what you&#8217;ve got conforms to an expected format. For example, if you&#8217;re expecting a US ZIP Code, make sure your value is either five digits or five digits, a hyphen, and four more digits (ZIP+4). Often, regular expressions are the easiest way to validate data:</p>
<pre>if (preg_match('/^\d{5}(-\d{4})?$/',$_GET['zip'])) {
    $zip = $_GET['zip'];
} else {
    die('Invalid ZIP Code format.');
}</pre>
<p>If you&#8217;re expecting to receive data in a cookie or a hidden form field that you&#8217;ve previously sent to a client, make sure it hasn&#8217;t been tampered with by sending a hash of the data and a secret word along with the data. Put the hash in a hidden form field (or in the cookie) along with the data. When you receive the data and the hash, re-hash the data and make sure the new hash matches the old one:</p>
<pre>// sending the cookie
$secret_word = 'gargamel';
$id = 123745323;
$hash = md5($secret_word.$id);
setcookie('id',$id.'-'.$hash);

// receiving and verifying the cookie
list($cookie_id,$cookie_hash) = explode('-',$_COOKIE['id']);
if (md5($secret_word.$cookie_id) == $cookie_hash) {
    $id = $cookie_id;
} else {
    die('Invalid cookie.');
}</pre>
<p>If a user has changed the ID value in the cookie, the hashes won&#8217;t match. The success of this method obviously depends on keeping <code>$secret_word</code> secret, so put it in a file that can&#8217;t be read by just anybody and change it periodically. (But remember, when you change it, old hashes that might be lying around in cookies will no longer be valid.)</p>
<p><strong>See Also:</strong></p>
<ul>
<li> PHP Manual: Using Register Globals</li>
<li>PHP Cookbook: Recipe 9.7 (&#8220;Securing PHP&#8217;s Form Processing&#8221;), Recipe 14.3 (&#8220;Verifying Data with Hashes&#8221;)</li>
</ul>
<h2>2. Broken Access Control</h2>
<p>Instead of rolling your own access control solution, use PEAR modules. <code>Auth</code> does cookie-based authentication for you and <code>Auth_HTTP</code> does browser-based authentication.</p>
<p><strong>See Also:</strong></p>
<ul>
<li>PEAR Packages: <a href="http://pear.php.net/package-info.php?package=Auth">Auth</a>, <a href="http://pear.php.net/package-info.php?package=Auth_HTTP">Auth_HTTP</a>.</li>
</ul>
<h2>3. Broken Account and Session Management</h2>
<p>Use PHP&#8217;s built-in session management functions for secure, standardized session management. However, be careful how your server is configured to store session information. For example, if session contents are stored as world-readable files in /tmp, then any user that logs into the server can see the contents of all the sessions. Store the sessions in a database or in a part of the file system that only trusted users can access.</p>
<p>To prevent network sniffers from scooping up session IDs, session-specific traffic should be sent over SSL. You don&#8217;t need to do anything special to PHP when you&#8217;re using an SSL connection, but you do need to specially configure your webserver.</p>
<p><strong>See Also:</strong></p>
<ul>
<li>PHP Manual: <a href="http://www.php.net/session">Session handling functions</a></li>
<li>PHP Cookbook: Recipe 8.5 (&#8220;Using Session Tracking&#8221;), Recipe 8.6 (&#8220;Storing Sessions in a Database&#8221;)</li>
</ul>
<h2>4. Cross-Site Scripting (XSS) Flaws</h2>
<p>Never display any information coming from outside your program without filtering it first. Filter variables before including them in hidden form fields, in query strings, or just plain page output.</p>
<p>PHP gives you plenty of tools to filter untrusted data:</p>
<ul>
<li><code>htmlspecialchars()</code> turns <code>&amp; &gt; " &lt;</code> into their HTML-entity equivalents and can also convert 	single quotes by passing <code>ENT_QUOTES</code> as a second argument.</li>
<li><code>strtr()</code> filters any characters you&#8217;d like. Pass <code>strtr()</code> an array of characters and their replacements. To change <code>(</code> and <code>)</code> into their entity equivalents, which is recommended to prevent XSS attacks, do:<br />
<code> $safer = strtr($untrusted, array('(' =&gt; '(', ')' =&gt; ')'));</code></li>
<li><code>strip_tags()</code> removes HTML and PHP tags from a string.</li>
<li><code>utf8_decode()</code> converts the ISO-8859-1 characters in a string encoded with the Unicode UTF-8 encoding to single-byte ASCII characters. Sometimes cross-site scripting attackers attempt to hide their attacks in Unicode encoding. You can use <code>utf8_decode()</code> to peel off that encoding.</li>
</ul>
<p><strong>See Also:</strong></p>
<ul>
<li>PHP Manual: <a href="http://www.php.net/htmlspecialchars">htmlspecialchars()</a>, <a href="http://www.php.net/strtr">strtr()</a>, <a href="http://www.php.net/strip-tags">strip_tags()</a>, <a href="http://www.php.net/utf8-decode">utf8_decode()</a></li>
<li>PHP Cookbook: Recipe 8.8 (&#8220;Building a GET Query String&#8221;), Recipe 9.8 (&#8220;Escaping Control Characters from User Data&#8221;)</li>
</ul>
<h2>5. Buffer Overflows</h2>
<p>You can&#8217;t allocate memory at runtime in PHP and their are no pointers like in C so your PHP code, however sloppy it may be, won&#8217;t have any buffer overflows. What you do have to watch out for, however, are buffer overflows in PHP itself (and its extensions.) Subscribe to the php-announce mailing list to keep abreast of patches and new releases.</p>
<p><strong>See Also:</strong></p>
<ul>
<li> PHP Mailing Lists: <a href="http://www.php.net/mailing-lists.php">http://www.php.net/mailing-lists.php</a></li>
</ul>
<h2>6. Command Injection Flaws</h2>
<p>Cross-site scripting flaws happen when you display unfiltered, unescaped malicious content to a user&#8217;s browser. Command injection flaws happen when you pass unfiltered, unescaped malicious commands to an external process or database. To prevent command injection flaws, in addition to validating input, always escape user input before passing it to an external process or database.</p>
<p>If you&#8217;re passing user input to a shell (via a command like <code>exec()</code>, <code>system()</code>, or the backtick operator), first, ask yourself if you really need to. Most file operations can be performed with native PHP functions. If you absolutely, positively need to run an external program whose name or arguments come from untrusted input, escape program names with <code>escapeshellcmd()</code> and arguments with <code>escapeshellarg()</code>.</p>
<p>Before executing an external program or opening an external file, you should also canonicalize its pathname with <code>realpath()</code>. This expands all symbolic links, translates <code>.</code> (current directory) <code>..</code> (parent directory), and removes duplicate directory separators. Once a pathname is canonicalized you can test it to make sure it meets certain criteria, like being beneath the web server document root or in a user&#8217;s home directory.</p>
<p>If you&#8217;re passing user input to a SQL query, escape the input with <code>addslashes()</code> before putting it into the query. If you&#8217;re using MySQL, escape strings with <code>mysql_real_escape_string()</code> (or <code>mysql_escape_string()</code> for PHP versions before 4.3.0). If you&#8217;re using the PEAR DB database abstraction layer, you can use the DB::quote() method or use a query placeholder like <code>?</code>, which automatically escapes the value that replaces the placeholder.</p>
<p><strong>See Also:</strong></p>
<ul>
<li> PHP Manual: <a href="http://www.php.net/escapeshellcmd">escapeshellcmd()</a>, <a href="http://www.php.net/escapeshellarg">escapeshellarg()</a>, <a href="http://www.php.net/realpath">realpath()</a>, <a href="http://www.php.net/addslashes">addslashes()</a>, <a href="http://www.php.net/mysql_real_escape_string">mysql_real_escape_string()</a>, <a href="http://www.php.net/mysql_escape_string">mysql_escape_string()</a></li>
<li> PEAR Package: <a href="http://pear.php.net/package-info.php?package=DB">DB</a>, DB Documentation</li>
<li> PHP Cookbook: Recipe 18.20 (&#8220;Escaping Shell Metacharacters&#8221;), Recipe 10.9 (&#8220;Escaping Quotes&#8221;)</li>
</ul>
<h2>7. Error Handling Problems</h2>
<p>If users (and attackers) can see the raw error messages returned from PHP, your database, or external programs, they can make educated guesses about how your system is organized and what software you use. These educated guesses make it easier for attackers to break into your system. Error messages shouldn&#8217;t contain any descriptive system information. Tell PHP to put error messages in your server&#8217;s error log instead of displaying them to a user with these configuration directives:</p>
<pre>log_errors = On
display_errors = Off</pre>
<p><strong>See Also:</strong></p>
<ul>
<li> PHP Manual: <a href="http://www.php.net/errorfunc">Error Handling and Logging Functions</a></li>
<li> PHP Cookbook: Recipe 8.14 (&#8220;Hiding Error Messages from Users&#8221;)</li>
</ul>
<h2>8. Insecure Use of Cryptography</h2>
<p>The <code>mcrypt</code> extension provides a standardized interface to many popular cryptographic algorithms. Use <code>mcrypt</code> instead of rolling your own encryption scheme. Also, be careful about where (if anywhere) you store encryption keys. The strongest algorithm in the world is pointless if an attacker can easily obtain a key for decryption. If you need to store keys at all, store them apart from encrypted data. Better yet, don&#8217;t store the keys and prompt users to enter them when something needs to be decrypted. (Of course, if you&#8217;re prompting a user over the web for sensitive information like an encryption key, that prompt and the user&#8217;s reply should be passed over SSL.)</p>
<p><strong>See Also:</strong></p>
<ul>
<li>PHP Manual: <a href="http://www.php.net/mcrypt">Mcrypt Encryption Functions</a></li>
<li>PHP Cookbook: Recipe 14.7 (&#8220;Encrypting and Decrypting Data&#8221;)</li>
</ul>
<h2>9. Remote Administration Flaws</h2>
<p>When possible, run remote administration tools over an SSL connection to prevent sniffing of passwords and content. If you&#8217;ve installed third-party software that has a remote administration component, change the default administrative user names and passwords. Change the default administrative URL as well, if possible. Running administrative tools on a different web server than the public web server that the administrative tool administrates can be a good idea as well.</p>
<h2>10. Web and Application Server Misconfiguration</h2>
<p>Keep on top of PHP patches and security problems by subscribing to the php-announce mailing list. Stay away from the automatic PHP source display handler (<code>AddType application/x-httpd-php-source .phps</code>), since it lets attackers look at your code. Of the two sample <code>php.ini</code> files distributed with PHP ( <code>php.ini-dist</code> and <code>php.ini-recommended</code>), use <code>php.ini-recommended</code> as a base for your site configuration.</p>
<p><em><strong>Read the Original Post at:</strong></em> <a href="http://www.sklar.com/page/article/owasp-top-ten" title="Original Post" target="_blank">http://www.sklar.com/page/article/owasp-top-ten</a></p>
]]></content:encoded>
			<wfw:commentRss>http://rochakchauhan.com/blog/2008/07/13/top-ten-security-vulnerabilities-in-php-code/feed/</wfw:commentRss>
		<slash:comments>373</slash:comments>
		</item>
		<item>
		<title>Using MVC in PHP Applications.</title>
		<link>http://rochakchauhan.com/blog/2008/02/23/using-mvc-in-php-applications/</link>
		<comments>http://rochakchauhan.com/blog/2008/02/23/using-mvc-in-php-applications/#comments</comments>
		<pubDate>Sat, 23 Feb 2008 06:57:05 +0000</pubDate>
		<dc:creator>rochakchauhan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://rochakchauhan.com/blog/2008/02/23/using-mvc-in-php-applications/</guid>
		<description><![CDATA[The Model-View-Controller (MVC) architecture provides a useful three-tier pattern for building software, as MVC patterns decouple the graphical user interface (GUI) from the application logic. That comes in useful when it comes to changing an application after it has been deployed. Separation of the views from the data means modifications made in the views do &#8230; <a class="read-excerpt" href="http://rochakchauhan.com/blog/2008/02/23/using-mvc-in-php-applications/">Continue reading <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The Model-View-Controller <a href="http://ootips.org/mvc-pattern.html" target="_blank">(MVC)</a>  architecture provides a useful three-tier pattern for building software, as MVC patterns decouple the graphical user interface (GUI) from the application logic.</p>
<p>That comes in useful when it comes to changing an application after it has been deployed. Separation of the views from the data means modifications made in the views do not affect the model and modifications made to the model to not effect the graphical user interface, simplifying maintenance. Also, an application may be expanded to add views and controllers that talk to a model without actually making any changes to the model itself.</p>
<p id="MidArticleAd"><script type="text/javascript">     document.write(\'\x3Cscript src="http://ad.uk.doubleclick.net/adj/reg.developer.4159/lifecycle;\'+RegExCats+GetVCs()+\'chl=;pid=\'+RegId+\';\'+RegKW+\'maid=\'+maid+\';test=\'+test+\';pf=\'+RegPF+\';dcove=d;sz=336x280;tile=3;ord=\' + rand + \'?" type="text/javascript">\x3C\/script>\');</script><script src="http://ad.uk.doubleclick.net/adj/reg.developer.4159/lifecycle;vc=print.print;vc=dev.lifecycle;chl=;pid=0;maid=;test=;pf=1;dcove=d;sz=336x280;tile=3;ord=16542149977661?" type="text/javascript"></script><noscript></noscript></p>
<p>Unfortunately for web developers, one of the features lacking in PHP until recently has been support for the MVC architecture. That has meant the MVC pattern has had to be implemented externally.</p>
<p>Some PHP frameworks have now added support for the MVC pattern, most notably the Zend Framework &#8211; one of the leading open-source PHP frameworks. Zend simplifies the task of developing secure, reliable web-based applications and web services. Zend provides an extensible code base, a flexible architecture and does not require any configuration files.</p>
<p>In this article we shall connect Zend to a database from Oracle, a company that&#8217;s been working closely to optimize its software with Zend.</p>
<h3>Fire up Zend</h3>
<p>The Zend framework requires at least PHP 5.1.4. It&#8217;s recommended to install PHP 5.2.2 or later because of the security and performance improvements in the newer version of PHP. Download the Zend Framework zip file <a href="http://framework.zend.com/download">from here</a> and &#8211; if you don&#8217;t already have it &#8211; download and install Apache 2.2.3, making sure it&#8217;s configured with PHP. Then, add the following <code>include_path</code> directive to <code>php.ini</code> configuration file:</p>
<pre>include_path=".;C:\ZendFramework\ZendFramework-1.0.1\library"</pre>
<p>Enable the PHP database extension for Oracle database in <code>php.ini</code>.</p>
<pre>extension=php_oci8.dll</pre>
<p>Restart Apache HTTP Server. Install the Oracle database including the sample schemas and create a table <code>Catalog</code> using SQL script <code>catalog.sql</code>.</p>
<h3>Create an MVC application</h3>
<p>Now it&#8217;s time to create a Create Read Update Delete (CRUD) application using Zend&#8217;s MVC architecture that&#8217;ll let us build, read, update, and delete an Oracle database table row.</p>
<p>In the MVC architecture the model represents the entities/class objects, the controller implements the business logic and integrates the model with the view, and the view represents the presentation layer or the user interface.</p>
<p>The MVC architecture in Zend Framework is implemented by the <code>Zend_Controller</code> component. The <code>Zend_Controller_Front</code> class provides a front controller for the MVC architecture. The front controller intercepts all requests and dispatches the requests to action controllers based on the request URL. The format of the request URL is <code>http://localhost/controller/action</code>. If no controller is specified the <code>index</code> controller and the <code>index</code> action are invoked. An action controller class extends the <code>Zend_Controller_Action</code> class. An action controller class is named with the notation <code>&lt;ControllerName&gt;Controller</code>. For example, the action controller class for the &#8220;index&#8221; controller is <code>IndexController</code>.</p>
<hr class="PageBreak" />Create a &#8220;controllers&#8221; directory and a &#8220;views&#8221; directory in the Apache web server document root <code>htdocs</code> by default. We shall create the view scripts in the &#8220;views&#8221; directory and controllers in the &#8220;controllers&#8221; directory. Create action controller, &#8220;database&#8221;, for the business logic of the MVC application. Create a <code>DatabaseController</code> class that extends the <code>Zend_Controller_Action</code> class and add action functions <code>insertAction</code>, <code>selectAction</code>, <code>updateAction</code>, and <code>deleteAction</code> to the class.The controller actions will be invoked from view scripts, which provide a user interface to specify the table row to be added, selected, updated and deleted. Create the view scripts <code>insertView.php</code>, <code>selectView.php</code>, <code>updateView.php</code>, and <code>deleteView.php</code> in the &#8220;views&#8221; directory. The view scripts and other resource files are available in a zipped resources file <a href="http://regmedia.co.uk/2008/02/21/php_zend_resources_zip.zip">here</a></p>
<h4>Add a row</h4>
<p>First, we shall add a row to the <code>Catalog</code> table. In the <code>insertView.php</code> add a form with input fields for the table row to be added. The &#8220;action&#8221; attribute of the <code>&lt;form&gt;</code> element specifies &#8220;database/insert&#8221;, which corresponds to the &#8220;insert&#8221; action of the &#8220;database&#8221; controller. In the <code>DatabaseController</code> <code>insertAction</code> function create a <code>Zend_Db</code> adapter, which represents a connection with Oracle database, using the <code>Zend_Db</code> factory.</p>
<pre>$params = array ('host'=&gt;'localhost','username'=&gt;'OE','password'=&gt;'pw','dbname'=&gt;'orcl'); $db=Zend_Db::factory('Oracle', $params);</pre>
<p>The first argument specifies the base name for the adapter class &#8211; &#8220;Oracle&#8221; for the Oracle database. The second argument specifies the adapter parameters. Retrieve the input fields specified in the <code>insertView.php</code> using <code>$_POST['field']</code> and create an associative array, <code>$row</code>, for the columns that constitute a row in the database table. Specify the database table to be updated and insert the new row using the <code>insert()</code> method of the <code>Zend_Db</code> adapter class.</p>
<pre>$table = 'Catalog'; $rowsAffected = $db-&gt;insert($table, $row);</pre>
<p>The first argument of the <code>insert()</code> method is the database table and the second argument is the associative array that maps column names to values. Invoke the <code>insertView.php</code> with URL <code>http://localhost/views/insertView.php</code>. To add a row specify the column values and click on create.</p>
<p class="CaptionedImage Center Float"><img src="http://regmedia.co.uk/2008/02/21/adding_a_row.jpg" alt="adding a row" title="adding a row" height="255" width="450" />Adding a row</p>
<h4>Retrieve a row</h4>
<p>Next, retrieve a row from the catalog table using the Zend Framework. Create a <code>Zend_Db_Select</code> object from the <code>Zend_Db</code> adapter object using the <code>select()</code> method.</p>
<pre>$select = $db-&gt;select();</pre>
<p>The <code>Zend_Db_Select</code> object is used to construct a SQL <code>SELECT</code> statement. Specify the <code>FROM</code> clause using the <code>from()</code> method and the <code>WHERE</code> clause using the <code>where()</code> method.</p>
<pre>$select-&gt;from('Catalog', '*'); $select-&gt;where('ID = ?', $_POST['id']);</pre>
<p>Create the SQL query string from the <code>Zend_Db_Select</code> object using the <code>_toString()</code> method. Run the SQL query using the <code>fetchAll()</code> method and query results will be returned as a row set.</p>
<pre>$sql = $select-&gt;__toString(); $rowset = $db-&gt;fetchAll($sql);</pre>
<p>Create a <code>Zend_View</code> object to render a view script and specify the directory containing the view scripts. The <code>Zend_View</code> class represents the &#8220;view&#8221; component of the model-view-controller pattern.</p>
<pre>$view = new Zend_View(); $view-&gt;setScriptPath('views');</pre>
<hr class="PageBreak" />Assign the row column values to the <code>Zend_View</code> instance. The variables assigned to the <code>Zend_View</code> object become the properties of the <code>Zend_View</code> object.</p>
<pre>$view-&gt;id = $_POST['id']; $view-&gt;journal = $rowset[0]["JOURNAL"]; $view-&gt;publisher = $rowset[0]["PUBLISHER"]; $view-&gt;edition = $rowset[0]["EDITION"]; $view-&gt;title = $rowset[0]["TITLE"]; $view-&gt;author = $rowset[0]["AUTHOR"];</pre>
<p>Create a view script, <code>resultView.php</code>, associated with the <code>Zend_View</code> object. The view script will run in the scope of the <code>Zend_View</code> object. References to <code>$this</code> in the view script are references to the <code>Zend_View</code> object. Create a table header and add values to the table using the <code>Zend_View</code> properties assigned in the action controller. In the <code>selectAction</code> function render the <code>resultView.php</code> script.</p>
<pre>echo $view-&gt;render('resultView.php');</pre>
<p>Invoke the <code>selectView.php</code> view script with the URL <code>http://localhost/views/selectView.php</code>. Specify the catalog ID for the row that is to be retrieved and click select.</p>
<p class="CaptionedImage Center Float"><img src="http://regmedia.co.uk/2008/02/21/select_database_table_row.jpg" alt="Selecting a database table row" title="Selecting a database table row" height="255" width="450" />Selecting a database table row</p>
<p>The row corresponding to the specified catalog ID will be retrieved and the results displayed.</p>
<h4>Update a Row</h4>
<p>Next, update a catalog table row using the Zend Framework. Create an associative array, <code>$data</code>, of column names and values for the row to be updated. Create a SQL expression specifying the <code>WHERE</code> clause for the ID of the row to be updated.</p>
<pre>$where[] = "ID ="."'".$_POST['id']."'";</pre>
<p>Update the database table using the <code>update()</code> method.</p>
<pre>$n = $db-&gt;update('Catalog', $data, $where);</pre>
<p>Invoke the <code>updateView.php</code> script with URL <code>http://localhost/views/updateView.php</code>. Specify the catalog ID of the row to be updated and the column values to be updated and click on update.</p>
<p class="CaptionedImage Center Float"><img src="http://regmedia.co.uk/2008/02/21/updating_database_table.jpg" alt="Updating database table" title="Updating database table" height="255" width="450" />Updating database table</p>
<p>A table row may be deleted using the <code>delete()</code> function.</p>
<p>MVC has a proven track record in simplifying the development and on-going maintenance of applications. Using Zend and the methodology I have outlined, you can now take advantage of MVC to simplify your work with PHP applications</p>
]]></content:encoded>
			<wfw:commentRss>http://rochakchauhan.com/blog/2008/02/23/using-mvc-in-php-applications/feed/</wfw:commentRss>
		<slash:comments>282</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
