<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>DotKernel PHP Application Framework</title>
	
	<link>http://www.dotkernel.com</link>
	<description>Implementation of  Zend Framework</description>
	<lastBuildDate>Fri, 30 Jul 2010 11:21:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/DotKernel" /><feedburner:info uri="dotkernel" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>PHP Environment : Development Staging Production</title>
		<link>http://feedproxy.google.com/~r/DotKernel/~3/uCUdOLEJlMo/</link>
		<comments>http://www.dotkernel.com/php-development/php-environment-development-staging-production/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 11:21:55 +0000</pubDate>
		<dc:creator>Teo</dc:creator>
				<category><![CDATA[PHP Development]]></category>

		<guid isPermaLink="false">http://www.dotkernel.com/?p=903</guid>
		<description><![CDATA[In hosted software development, the environment refers to a server tier designated to a specific stage in a release process. The purpose of these environments is to improve the development, testing and release processes in client-server applications. The most common &#8230; <a href="http://www.dotkernel.com/php-development/php-environment-development-staging-production/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In hosted software development, the environment refers to a server tier designated to a specific stage in a release process. The purpose of these environments is to improve the development, testing and release processes in client-server applications. The most common environments are described below.</p>
<h3>Development</h3>
<p>This is where the software is developed – it’s<em> the working environment for individual developers</em> or small teams. The purpose of this environment is for the developer to work on local host, separate from the rest of the team, allowing them to make various changes without worrying that it may alter the work of the other members of the team.</p>
<h3>Staging</h3>
<p>It is <em>used to assemble, test and review the application before it goes into production</em>. Usually the staging environment tries to simulate as much as possible the production environment (hardware and software-wise). Normally, before releasing an update version of the application on the production environment, the update must be tested on the staging environment. This environment can also be used as a demonstration/training environment.</p>
<h3>Production</h3>
<p>It is <em>the “live” environment</em>, where the final application goes out to the world and becomes active.</p>
<p>To switch from one environment to another use the <em><strong>Subversion</strong></em> <em>source code</em>.</p>
<p><a title=" Downloaded 171 times" href="../download/?did=6">Using SVN on Aptana</a> is an article that explains how to set your <em>development </em>environment on your local computer and then to change it on your <em>staging </em>environment.</p>
<p>To better understand the development of an application using environments, check this helpful article <a href="http://dltj.org/article/software-development-practice/">http://dltj.org/article/software-development-practice/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotkernel.com/php-development/php-environment-development-staging-production/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.dotkernel.com/php-development/php-environment-development-staging-production/</feedburner:origLink></item>
		<item>
		<title>DotKernel 1.2.2 release</title>
		<link>http://feedproxy.google.com/~r/DotKernel/~3/RqeBis9ylk0/</link>
		<comments>http://www.dotkernel.com/dotkernel/dotkernel-1-2-2-release/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 09:10:12 +0000</pubDate>
		<dc:creator>Teo</dc:creator>
				<category><![CDATA[DotKernel]]></category>

		<guid isPermaLink="false">http://www.dotkernel.com/?p=887</guid>
		<description><![CDATA[Yesterday, we released DotKernel 1.2.2. It contains some bug fixes: 31 – captcha errors try catch 32 – pagination issue 33 – Admin wrong link 34 – Acunetix results July 24th ( notices and one fatal error) 35 – update &#8230; <a href="http://www.dotkernel.com/dotkernel/dotkernel-1-2-2-release/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Yesterday, we released <strong>DotKernel 1.2.2</strong>. It contains some bug fixes:</p>
<ul>
<li><span style="text-decoration: line-through;"><a href="http://www.dotkernel.net/view.php?id=31">31</a></span> – captcha errors try catch</li>
<li><span style="text-decoration: line-through;"><a href="http://www.dotkernel.net/view.php?id=32">32</a></span> – pagination issue</li>
<li><span style="text-decoration: line-through;"><a href="http://www.dotkernel.net/view.php?id=33">33</a></span> – Admin wrong link</li>
<li><span style="text-decoration: line-through;"><a href="http://www.dotkernel.net/view.php?id=34">34</a></span> – Acunetix results July 24th ( notices and one fatal error)</li>
<li><span style="text-decoration: line-through;"><a href="http://www.dotkernel.net/view.php?id=35">35</a></span> – update copyright line in files</li>
</ul>
<p>For more details see <a href="../changelog/1-2-2/">ChangeLog 1.2.2</a>. To get only the changed files from 1.2.1 to 1.2.2, download the <a href="../download/?did=17">upgrade</a> file</p>
<p><strong>Note*</strong>: because of the Bug 35, all php files have changed. To see what else has changed, check the <a href="http://www.dotkernel.net/">DotKernel Tracker</a> or the <a href="http://websvn.dotkernel.net/listing.php?repname=DotKernel+ver.+1">DotKernel WebSVN</a> .</p>
<p><em>P.S.</em> On July 22, 2010 we released <em>DotKernel 1.2.1.</em> You can check the <a href="../changelog/1-2-1/">ChangeLog 1.2.1</a> or download <a href="../download/?did=14">the upgrade 1.2.1</a> zip file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotkernel.com/dotkernel/dotkernel-1-2-2-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.dotkernel.com/dotkernel/dotkernel-1-2-2-release/</feedburner:origLink></item>
		<item>
		<title>End of Support for PHP 5.2.x Branch</title>
		<link>http://feedproxy.google.com/~r/DotKernel/~3/dfDGF2dM3xM/</link>
		<comments>http://www.dotkernel.com/php-development/end-of-support-for-php-5-2-x-branch/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 20:53:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Development]]></category>

		<guid isPermaLink="false">http://www.dotkernel.com/?p=790</guid>
		<description><![CDATA[PHP 5.2.14 was just released . And this is the end of support for 5.2.x branch of PHP . NOTE:This release marks the end of the active support for PHP 5.2. Following this release the PHP 5.2 series will receive &#8230; <a href="http://www.dotkernel.com/php-development/end-of-support-for-php-5-2-x-branch/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.php.net/ChangeLog-5.php#5.2.14" target="_blank">PHP 5.2.14</a> was just released . And this is the end of support for 5.2.x branch of PHP .</p>
<blockquote><p><strong>NOTE:</strong>This release marks the end of the active support  for PHP 5.2. Following this release the PHP 5.2 series will receive no  further active bug maintenance. Security fixes for PHP 5.2 might be  published on a case by cases basis. All users of PHP 5.2 are encouraged  to upgrade to PHP 5.3</p></blockquote>
<p><a href="http://www.php.net/ChangeLog-5.php#5.3.3" target="_blank"> PHP 5.3.3</a> is just released ,  so is time to upgrade every project  to PHP 5.3.x branch, and also upgrade all servers to 5.3.x</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotkernel.com/php-development/end-of-support-for-php-5-2-x-branch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.dotkernel.com/php-development/end-of-support-for-php-5-2-x-branch/</feedburner:origLink></item>
		<item>
		<title>DotKernel 1.2.0 release</title>
		<link>http://feedproxy.google.com/~r/DotKernel/~3/ssccj3ZXpk4/</link>
		<comments>http://www.dotkernel.com/dotkernel/dotkernel-1-2-0-release/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 13:36:10 +0000</pubDate>
		<dc:creator>Teo</dc:creator>
				<category><![CDATA[DotKernel]]></category>

		<guid isPermaLink="false">http://www.dotkernel.com/?p=548</guid>
		<description><![CDATA[Finally we reached DotKernel 1.2.0 milestone. Since the previous released 1.1.2, some changes have been made. On database, we changed the names and structure of tables to respect database naming convention. http://www.dotkernel.com/dotkernel/dotkernel-database-naming-conventions-for-mysql/ A new word came into our DotKernel discussions: &#8230; <a href="http://www.dotkernel.com/dotkernel/dotkernel-1-2-0-release/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Finally we reached DotKernel 1.2.0 milestone.</p>
<p>Since the previous released 1.1.2, some changes have been made.</p>
<ul>
<li>On database, we changed the names and structure of tables to respect database naming convention. <a href="../dotkernel/dotkernel-database-naming-conventions-for-mysql/"><em>http://www.dotkernel.com/dotkernel/dotkernel-database-naming-conventions-for-mysql/</em></a></li>
</ul>
<ul>
<li>A new word came into our DotKernel discussions: <strong><em>dots.</em></strong> We use this term when talking about a submodule and all its component files. For example, <em>“user”</em> is a submodule of <em>frontend</em> module. Note that one dots can be part of multiple modules. (For example, <em>“user”</em> dots belong to <em>frontend</em> and <em>admin</em> module). For each dots, the configurations values have been added to xml files which are stored in <em>configs/dots</em> folder. In the preview versions, this values where hard-coded in the php files.</li>
</ul>
<ul>
<li>Another change made in <em>configs </em>folder is <em>resource.xml</em>, which contains the configuration values for the controllers of each module.</li>
</ul>
<p>To be easier to start an application from DotKernel, in admin module, there are now the following dots:  admin, user and system.</p>
<p>New library classes have been implemented: Dot_Geoip and Dot_Seo, and some of the existing ones have been updated: Dot_Curl and Dot_Session (each module has his own session).</p>
<p>In DotKernel, all SQL queries are written as prepared statements.  We strongly encourage this  practice: <em><a href="../php-development/protection-against-sql-injection-using-pdo-and-zend-framework/">http://www.dotkernel.com/php-development/protection-against-sql-injection-using-pdo-and-zend-framework/</a></em></p>
<p>For more details, see  <a title=http://www.dotkernel.com/changelog/1-2-0/" href="http://www.dotkernel.com/changelog/1-2-0/">ChangeLog 1.2.0</a></p>
<p><em><br />
</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotkernel.com/dotkernel/dotkernel-1-2-0-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.dotkernel.com/dotkernel/dotkernel-1-2-0-release/</feedburner:origLink></item>
		<item>
		<title>Why use CURRENT_TIMESTAMP on a field that record date/time?</title>
		<link>http://feedproxy.google.com/~r/DotKernel/~3/or_tkh-_14w/</link>
		<comments>http://www.dotkernel.com/best-practice/why-use-current_timestamp-on-a-datetime-field/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 15:04:05 +0000</pubDate>
		<dc:creator>Teo</dc:creator>
				<category><![CDATA[Best Practice]]></category>

		<guid isPermaLink="false">http://www.dotkernel.com/?p=553</guid>
		<description><![CDATA[On a TIMESTAMP field that records date and time when inserting a new record, it is encouraged to use as a DEFAULT value, the CURRENT_TIMESTAMP constant. Why? Because when inserting a new row in the table for the date and &#8230; <a href="http://www.dotkernel.com/best-practice/why-use-current_timestamp-on-a-datetime-field/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>On a <em>TIMESTAMP field</em> that records date and time when <em>inserting </em>a new record, it is encouraged to use as a <em>DEFAULT </em>value, the <strong>CURRENT_TIMESTAMP</strong> constant.</p>
<p><strong>Why? </strong></p>
<p>Because when inserting a new row in the table for the date and time field there is no need to specifically add its value, either by creating it from PHP code with the <a href="http://www.php.net/manual/en/ref.datetime.php">Date/ Time functions</a> or with MySQL function <a href="http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_now">NOW()</a></p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">ALTER</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`user`</span> CHANGE <span style="color: #008000;">`dateCreated`</span> <span style="color: #008000;">`dateCreated`</span> <span style="color: #999900; font-weight: bold;">TIMESTAMP</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">DEFAULT</span> <span style="color: #000099;">CURRENT_TIMESTAMP</span><span style="color: #000033;">;</span></pre></div></div>

<p>CURRENT_TIMESTAMP is also a solution for  <em>updating </em>date and time fields. Use <em><code>ON UPDATE CURRENT_TIMESTAMP</code></em> clause, if you want the value of the field to be changed automatically each time the row is updated.</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">ALTER</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`user`</span> CHANGE <span style="color: #008000;">`dateLogin`</span> <span style="color: #008000;">`dateLogin`</span> <span style="color: #999900; font-weight: bold;">TIMESTAMP</span> <span style="color: #990099; font-weight: bold;">ON</span> <span style="color: #990099; font-weight: bold;">UPDATE</span> <span style="color: #000099;">CURRENT_TIMESTAMP</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">DEFAULT</span> <span style="color: #000099;">CURRENT_TIMESTAMP</span><span style="color: #000033;">;</span></pre></div></div>

<p><em>DEFAULT </em>and <em>ON UPDATE</em> clauses can be used together or separately, depending on your needs:</p>
<ul>
<li>With both <code>DEFAULT CURRENT_TIMESTAMP</code> and <code>ON UPDATE CURRENT_TIMESTAMP</code> clauses, the column has the current timestamp for its default value and is automatically updated.</li>
<li>With neither <code>DEFAULT</code> nor <code>ON UPDATE</code> clauses, it is the same as <code>DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP</code>. (Only for the <em><span style="text-decoration: underline;">first </span></em>TIMESTAMP field from the table)</li>
<li>With a <code>DEFAULT CURRENT_TIMESTAMP</code> clause and no <code>ON UPDATE</code> clause, the column has the current timestamp for its default value but is not automatically updated.</li>
<li>With no <code>DEFAULT</code> clause and with an <code>ON UPDATE CURRENT_TIMESTAMP</code> clause, the column has a default of 0 and is automatically updated.</li>
<li>With a constant <code>DEFAULT</code> value, the column has the given default and is not automatically initialized to the current timestamp. If the column also has an <code>ON UPDATE CURRENT_TIMESTAMP</code> clause, it is automatically updated; otherwise, it has a constant default and is not automatically updated.</li>
</ul>
<p>For more details check out <a href="http://dev.mysql.com/doc/refman/5.0/en/timestamp.html">MySQL Manual</a></p>
<p><strong>Note*:</strong> Only one timestamp field can be <code>DEFAULT CURRENT_TIMESTAMP</code> in a table.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotkernel.com/best-practice/why-use-current_timestamp-on-a-datetime-field/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.dotkernel.com/best-practice/why-use-current_timestamp-on-a-datetime-field/</feedburner:origLink></item>
		<item>
		<title>Protection against SQL Injection using PDO and Zend Framework – part 2</title>
		<link>http://feedproxy.google.com/~r/DotKernel/~3/sgqKkA-0ZpM/</link>
		<comments>http://www.dotkernel.com/php-development/protection-against-sql-injection-using-pdo-and-zend-framework-part-2/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 12:37:19 +0000</pubDate>
		<dc:creator>Teo</dc:creator>
				<category><![CDATA[Best Practice]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[SQL Injection]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.dotkernel.com/?p=526</guid>
		<description><![CDATA[Following the preview article about SQL Injection, here is more &#8211; a strong argument why you should use Zend Framework for handling database access. Zend_Db is the primary class used for access the database, but there is more: Zend_Db_Statement, Zend_Db_Select &#8230; <a href="http://www.dotkernel.com/php-development/protection-against-sql-injection-using-pdo-and-zend-framework-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Following the preview article about <a title="Protection against SQL Injection using PDO and Zend Framework" href="http://www.dotkernel.com/php-development/protection-against-sql-injection-using-pdo-and-zend-framework/" target="_self">SQL Injection</a>, here is more &#8211; a strong argument why you should use Zend Framework for handling database access. <em>Zend_Db</em> is the primary class used for access the database, but there is more: <em>Zend_Db_Statement</em>, <em>Zend_Db_Select</em> and <em>Zend_Db_Tables</em>.<br />
What you should know about their methods is:</p>
<ul>
<li><em><a title="details" href="http://framework.zend.com/apidoc/core/Zend_Db/Adapter/Zend_Db_Adapter_Abstract.html#query">query</a> (mixed $sql,  [mixed $bind  = array()])</em>
<ul>
<li>use prepare statements internally</li>
<li>but SQL Injection is still possible if $sql is dynamically created</li>
</ul>
</li>
<li><em><a title="details" href="http://framework.zend.com/apidoc/core/Zend_Db/Adapter/Zend_Db_Adapter_Abstract.html#fetchAll">fetchAll</a> (string|Zend_Db_Select $sql, [mixed $bind = array()],  [mixed $fetchMode  = null])</em>
<ul>
<li>all the fetch methods are using prepared statements internally</li>
<li>but SQL Injection is still possible if $sql is dynamically created</li>
</ul>
</li>
<li><em><a title="details" href="http://framework.zend.com/apidoc/core/Zend_Db/Adapter/Zend_Db_Adapter_Abstract.html#insert">insert</a> (mixed $table,   $bind)</em>
<ul>
<li>use prepare statements internally</li>
<li>so, SQL Injection is not possible</li>
</ul>
</li>
<li><em><a title="details" href="http://framework.zend.com/apidoc/core/Zend_Db/Adapter/Zend_Db_Adapter_Abstract.html#update">update</a> (mixed $table,   $bind, [mixed $where = ''])</em>
<ul>
<li>use prepare statements internally</li>
</ul>
<ul>
<li>but SQL Injection may be possible if $where is created dynamically</li>
</ul>
</li>
<li><em><a title="details" href="http://framework.zend.com/apidoc/core/Zend_Db/Adapter/Zend_Db_Adapter_Abstract.html#delete">delete</a> (mixed $table,  [mixed $where  = ''])</em>
<ul>
<li>SQL Injection may be possible if $where is created dynamically</li>
</ul>
</li>
</ul>
<p><em><strong>Note*:</strong></em> even if you use prepared statements using <em>Zend_Db</em> methods, SQL Injection is still possible if <em>WHERE </em>and <em>ORDER BY</em> clause are wrongly written, so pay attention to them.</p>
<p>For more details see <a title="Secure Programming with the Zend-Framework" href="http://www.suspekt.org/downloads/DPC_Secure_Programming_With_The_Zend_Framework.pdf" target="_blank">Stefan Esser slides</a>.</p>
<p>PS. A short <a href="http://www.dustinweber.com/main-page/type-casting-in-php-whats-the-point/">tip</a>, you can use cast type to avoid SQL Injection in WHERE clause where is possible.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$sql</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">'SELECT * FROM table WHERE id = '</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.dotkernel.com/php-development/protection-against-sql-injection-using-pdo-and-zend-framework-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.dotkernel.com/php-development/protection-against-sql-injection-using-pdo-and-zend-framework-part-2/</feedburner:origLink></item>
		<item>
		<title>Protection against SQL Injection using  PDO and Zend Framework</title>
		<link>http://feedproxy.google.com/~r/DotKernel/~3/br_GmANoZ6g/</link>
		<comments>http://www.dotkernel.com/php-development/protection-against-sql-injection-using-pdo-and-zend-framework/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 15:21:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Best Practice]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[SQL Injection]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.dotkernel.com/?p=524</guid>
		<description><![CDATA[SQL injection is a technique that exploits a security vulnerability occurring in the database layer of an application. Usually, user input is not filtered by the script and is passed into a SQL statement. PDO – PHP Data Objects – &#8230; <a href="http://www.dotkernel.com/php-development/protection-against-sql-injection-using-pdo-and-zend-framework/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>SQL injection is a technique that exploits a security vulnerability occurring in the database layer of an application. Usually, <em>user input is not filtered by the script and is passed into a SQL statement.</em></p>
<p><strong>PDO – PHP Data Objects </strong>– is a database access layer providing a standardized method of access to multiple databases.  PDO provides a <em>data-access abstraction layer</em>, meaning that depending on what database you&#8217;re using, you will have apply the same functions to issue queries and fetch data. <strong><em>PDO does not provide a database abstraction;</em></strong> it doesn&#8217;t rewrite SQL or emulate missing features. Among  PDO benefits there are:<br />
-    Access methods allow complete control over how attributes are read and written<br />
-    Validation on a per-record and per-attribute level<br />
-    Easier fetching of objects from related table<br />
-    Reusable logic &#8211; means that the same codebase is much easier to maintain<br />
-    Cleaner code by using object oriented code<br />
-    Less errors from SQL query generation<br />
-    Last but not least : Protection against SQL injection</p>
<p>In Zend Framework for database access, methods usually support prepared statements. Dynamic SQL queries are allowed, but you must escape all the parameter, otherwise you have SQL injection.  <strong><em>Because of this, prepared statements are encouraged to be used. They can handle escaping parameters for you.</em></strong><br />
Most people believe that using prepared statements they are 100% protected from SQL injection. But this is by far true. Input data should always be validated and sanitized, and PDO should be seen as another line of defense. PDO is not protecting you from other security vulnerabilities like XSS<em>(cross-site scripting)</em>, but helps protect your application against SQL injection.</p>
<p>It may also occur a problem in Zend Framework w<em>hen you have SQL injection in your application while you are using PDO_MySQL.</em> <em><strong>PDO_MySQL is a more dangerous application than any other traditional MySQL applications. Traditional MySQL allows only a single SQL query. In PDO_MySQL there is no such limitation, but you risk to be injected with multiple queries.</strong> </em>To avoid this you should try to use the correct prepared statements from Zend Framework. You should also pay attention when you have in your SQL query <em>WHERE IN</em> and <em>ORDER BY;</em> they cannot be handled by prepare statements normally. In this case you should escape your data.</p>
<p>Zend_Db has two escaping methods which can be used: <em>quote()</em> and <em>quoteIdentifier()</em>. Note that these two methods are handling strings by putting them between single quotes.</p>
<p>For more details see:</p>
<p><a href="http://ezinearticles.com/?SQL-Injection-Protection-in-PHP-With-PDO&amp;id=1815110" target="_blank">http://ezinearticles.com/?SQL-Injection-Protection-in-PHP-With-PDO&amp;id=1815110</a></p>
<p><a href="http://www.zend.com/webinar/Framework/70170000000bEs9-webinar-secure-application-development-with-the-ZF-20100505.flv" target="_blank">http://www.zend.com/webinar/Framework/70170000000bEs9-webinar-secure-application-development-with-the-ZF-20100505.flv</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotkernel.com/php-development/protection-against-sql-injection-using-pdo-and-zend-framework/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.dotkernel.com/php-development/protection-against-sql-injection-using-pdo-and-zend-framework/</feedburner:origLink></item>
		<item>
		<title>INSERT, UPDATE, DELETE statements with Zend_Db</title>
		<link>http://feedproxy.google.com/~r/DotKernel/~3/ZXAQYfXFaCY/</link>
		<comments>http://www.dotkernel.com/best-practice/iud-statements-with-zend-db/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 08:58:13 +0000</pubDate>
		<dc:creator>Teo</dc:creator>
				<category><![CDATA[Best Practice]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Zend_Db]]></category>

		<guid isPermaLink="false">http://www.dotkernel.com/?p=507</guid>
		<description><![CDATA[Continuing the Zend_DB article series, we are stopping now at DML statements. DML (Data Manipulation Language) statements are statements that change data values in database tables. There are 3 primary DML statements: INSERT &#8211; Inserting new rows into database tables. &#8230; <a href="http://www.dotkernel.com/best-practice/iud-statements-with-zend-db/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Continuing the Zend_DB article <a href="http://www.dotkernel.com/dotkernel/sql-select-zend-db/"  target="_blank">series</a>, we are stopping now at DML statements.</br><br />
DML (Data Manipulation Language) statements are statements that change data values in database tables. There are 3 primary DML statements:</p>
<ul>
<li>INSERT &#8211; Inserting new rows into database tables.
<li>UPDATE &#8211; Updating existing rows in database tables .
<li>DELETE &#8211; Deleting existing rows from database tables.
</ul>
<p></br><br />
<i>Note*: </i></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> Zend_Db<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Pdo_Mysql'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbConnect</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p></br><br />
<b>INSERT</b></p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> <span style="color: #000099;">user</span><span style="color: #FF00FF;">&#40;</span>email<span style="color: #000033;">,</span> <span style="color: #000099;">password</span><span style="color: #000033;">,</span> firstName<span style="color: #000033;">,</span> lastName<span style="color: #000033;">,</span> active<span style="color: #FF00FF;">&#41;</span>
	   <span style="color: #990099; font-weight: bold;">VALUES</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'$email'</span><span style="color: #000033;">,</span> <span style="color: #008000;">'$password'</span><span style="color: #000033;">,</span> <span style="color: #008000;">'$firstName'</span><span style="color: #000033;">,</span> <span style="color: #008000;">'$lastName'</span><span style="color: #000033;">,</span> <span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></div></div>

<p>The above SQL <i>INSERT</i> statement is translated in Zend_Db as follow:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'email'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$email</span><span style="color: #339933;">,</span>
		    <span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span>
		    <span style="color: #0000ff;">'firstName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$firstName</span><span style="color: #339933;">,</span>
		    <span style="color: #0000ff;">'lastName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$lastName</span><span style="color: #339933;">,</span>
		    <span style="color: #0000ff;">'active'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p></br><br />
<b>UPDATE</b></p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">UPDATE</span> <span style="color: #000099;">user</span>
   <span style="color: #990099; font-weight: bold;">SET</span> <span style="color: #000099;">password</span> <span style="color: #CC0099;">=</span> <span style="color: #008000;">'$password'</span><span style="color: #000033;">,</span>
       firstName <span style="color: #CC0099;">=</span> <span style="color: #008000;">'$firstName'</span><span style="color: #000033;">,</span>
       lastName <span style="color: #CC0099;">=</span> <span style="color: #008000;">'$lastName'</span><span style="color: #000033;">,</span>
       accountUpdate <span style="color: #CC0099;">=</span> <span style="color: #FF00FF;">&#40;</span>accountUpdate <span style="color: #CC0099;">+</span><span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span>
 <span style="color: #990099; font-weight: bold;">WHERE</span> id <span style="color: #CC0099;">=</span> <span style="color: #008000;">'$id'</span></pre></div></div>

<p>The above SQL <i>UPDATE</i> statemnet is translated in Zend_Db as follow:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'firstName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$firstName</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'lastName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$vlastname</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'accountUpdate'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Db_Expr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'accountUpdate+1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'id = '</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p></br><br />
<b>DELETE</b></p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">DELETE</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #000099;">user</span> <span style="color: #990099; font-weight: bold;">WHERE</span> id <span style="color: #CC0099;">=</span> <span style="color: #008000;">'$id'</span></pre></div></div>

<p>The above SQL <i>DELETE</i> statemnet is translated in Zend_Db as follow:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'id = '</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.dotkernel.com/best-practice/iud-statements-with-zend-db/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.dotkernel.com/best-practice/iud-statements-with-zend-db/</feedburner:origLink></item>
		<item>
		<title>Subqueries with Zend_Db</title>
		<link>http://feedproxy.google.com/~r/DotKernel/~3/jalE3SLv-r8/</link>
		<comments>http://www.dotkernel.com/best-practice/subqueris-with-zend-db/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 14:00:45 +0000</pubDate>
		<dc:creator>Teo</dc:creator>
				<category><![CDATA[Best Practice]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Zend_Db]]></category>

		<guid isPermaLink="false">http://www.dotkernel.com/?p=497</guid>
		<description><![CDATA[Continuing the Zend_DB article series, we are stopping now at subqueries. As you note, the below is a complicate query, with COUNT(), LEFT JOIN(), GROUP BY &#8211; select from 3 tables, and make a count from 2 different tables: SELECT &#8230; <a href="http://www.dotkernel.com/best-practice/subqueris-with-zend-db/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Continuing the Zend_DB article <a href="http://www.dotkernel.com/dotkernel/sql-select-zend-db/"  target="_blank">series</a>, we are stopping now at subqueries.<br />
</br><br />
As you note, the below is a complicate query, with <i>COUNT()</i>, <i>LEFT JOIN()</i>, <i>GROUP BY</i><br />
 &#8211; select from 3 tables, and make a count from 2 different tables:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> a.id<span style="color: #000033;">,</span>
	   a.title<span style="color: #000033;">,</span> 
       <span style="color: #FF00FF;">&#40;</span><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">COUNT</span><span style="color: #FF00FF;">&#40;</span>c.track_id<span style="color: #FF00FF;">&#41;</span>
        <span style="color: #990099; font-weight: bold;">FROM</span> track_files <span style="color: #990099; font-weight: bold;">AS</span> c 
        <span style="color: #990099; font-weight: bold;">WHERE</span> c.track_id <span style="color: #CC0099;">=</span> a.id
       <span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> <span style="color: #008000;">`count<span style="color: #008080; font-weight: bold;">_</span>files`</span><span style="color: #000033;">,</span>
       <span style="color: #000099;">COUNT</span><span style="color: #FF00FF;">&#40;</span>b.track_id<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> count_courses
<span style="color: #990099; font-weight: bold;">FROM</span> tracks <span style="color: #990099; font-weight: bold;">AS</span> a 
<span style="color: #000099;">LEFT</span> <span style="color: #990099; font-weight: bold;">JOIN</span> track_courses <span style="color: #990099; font-weight: bold;">AS</span> b <span style="color: #990099; font-weight: bold;">ON</span> <span style="color: #FF00FF;">&#40;</span>a.id <span style="color: #CC0099;">=</span> b.track_id<span style="color: #FF00FF;">&#41;</span>
<span style="color: #990099; font-weight: bold;">GROUP BY</span> a.id</pre></div></div>

<p></br><br />
Initialize the connection to our MySql database:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> Zend_Db<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Pdo_Mysql'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbConnect</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p></br></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'tracks'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	     <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span>
	 	     <span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span>
		     <span style="color: #0000ff;">'count_files'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Db_Expr<span style="color: #009900;">&#40;</span>
			 		   <span style="color: #0000ff;">'('</span><span style="color: #339933;">.</span><span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
						   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'c'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'track_files'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
						             <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Zend_Db_Expr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'COUNT(c.track_id)'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
						   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'c.track_id = a.id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">')'</span> <span style="color: #009900;">&#41;</span>
			   <span style="color: #009900;">&#41;</span>
		  <span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">joinLeft</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'b'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'track_courses'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		 <span style="color: #0000ff;">'a.id = b.track_id'</span><span style="color: #339933;">,</span>
		 <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'count_courses'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'COUNT(b.track_id)'</span><span style="color: #009900;">&#41;</span>
		 <span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">group</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a.id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.dotkernel.com/best-practice/subqueris-with-zend-db/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.dotkernel.com/best-practice/subqueris-with-zend-db/</feedburner:origLink></item>
		<item>
		<title>What are returning the FETCH functions from Zend_Db</title>
		<link>http://feedproxy.google.com/~r/DotKernel/~3/bJn5LxGTHTQ/</link>
		<comments>http://www.dotkernel.com/best-practice/sql-fetch-zend-db/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 13:36:20 +0000</pubDate>
		<dc:creator>Teo</dc:creator>
				<category><![CDATA[Best Practice]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Zend_Db]]></category>

		<guid isPermaLink="false">http://www.dotkernel.com/?p=491</guid>
		<description><![CDATA[Continuing the Zend_DB article series, we are stopping now at FETCH methods that are in Zend_Db_Adapter_Abstract: array fetchAll &#40;string&#124;Zend_Db_Select $sql, &#91;mixed $bind = array&#40;&#41;&#93;, &#91;mixed $fetchMode = null&#93;&#41; array fetchAssoc &#40;string&#124;Zend_Db_Select $sql, &#91;mixed $bind = array&#40;&#41;&#93;&#41; array fetchCol &#40;string&#124;Zend_Db_Select $sql, &#8230; <a href="http://www.dotkernel.com/best-practice/sql-fetch-zend-db/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Continuing the Zend_DB article <a href="http://www.dotkernel.com/dotkernel/sql-select-zend-db/"  target="_blank">series</a>, we are stopping now at <i>FETCH</i> methods that are in <a href="http://framework.zend.com/apidoc/core/Zend_Db/Adapter/Zend_Db_Adapter_Abstract.html#sec-method-summary"  target="_blank">Zend_Db_Adapter_Abstract</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">array</span>  fetchAll  <span style="color: #009900;">&#40;</span>string<span style="color: #339933;">|</span>Zend_Db_Select <span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>mixed <span style="color: #000088;">$bind</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>mixed <span style="color: #000088;">$fetchMode</span>  <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #990000;">array</span> fetchAssoc <span style="color: #009900;">&#40;</span>string<span style="color: #339933;">|</span>Zend_Db_Select <span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>mixed <span style="color: #000088;">$bind</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #990000;">array</span> fetchCol <span style="color: #009900;">&#40;</span>string<span style="color: #339933;">|</span>Zend_Db_Select <span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>mixed <span style="color: #000088;">$bind</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
string fetchOne <span style="color: #009900;">&#40;</span>string<span style="color: #339933;">|</span>Zend_Db_Select <span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>mixed <span style="color: #000088;">$bind</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #990000;">array</span> fetchPairs <span style="color: #009900;">&#40;</span>string<span style="color: #339933;">|</span>Zend_Db_Select <span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>mixed <span style="color: #000088;">$bind</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #990000;">array</span> fetchRow <span style="color: #009900;">&#40;</span>string<span style="color: #339933;">|</span>Zend_Db_Select <span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>mixed <span style="color: #000088;">$bind</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>mixed <span style="color: #000088;">$fetchMode</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>To be more easily to follow, in <span style="background-color: #B5DFC1">green</span> box is the classical SQL statement, and in <span style="background-color:  #9FCFFF">blue</span> box is the query written in Zend_Db style.<br />
</br><br />
Lets start.<br />
Initialize the connection to our MySql database:</p>
<pre lang="php" style="background-color: #9FCFFF">
$db = Zend_Db::factory('Pdo_Mysql', $dbConnect);
</pre>
<p>Here is a SQL query, that we want to fetch:<br />
</br></p>
<pre lang="php" style="background-color: #B5DFC1">
$sql = "SELECT id, title FROM files";
$db->query($sql)
</pre>
<p></br></p>
<pre lang="php" style="background-color: #9FCFFF">
$select = $db->select()
             ->from('files', array('id', 'title'))
</pre>
<p><i>Note*:</i> for the old style of fetching we used an old class. What you need to know is: </br><br />
- <i>query()</i> method is similar with mysqli_query() from <i>Mysqli</i> PHP extension </br><br />
- <i>next_record()</i> method is similar with mysqli_next_result() from <i>Mysqli</i> PHP extension </br><br />
- <i>f()</i> method retrieve the value of the column specified as parameter<br />
</br><br />
<b>fetchAll</b><br />
</br></p>
<pre lang="php" style="background-color: #B5DFC1">
while($db->next_record())
{
    $a[] = array(
				 'id' => $db->f('id'),
				 'title' => $db->f('title')
		     	);
}
</pre>
<p></br></p>
<pre lang="php" style="background-color: #9FCFFF">
$a = $db->fetchAll($select);
</pre>
<p></br><br />
<b>fetchAssoc</b><br />
</br></p>
<pre lang="php" style="background-color: #B5DFC1">
while($db->next_record())
{
	$a[$db->f('id')] = array(
							 'id' => $db->f('id'),
							 'title' => $db->f('title')
							);
}
</pre>
<p></br></p>
<pre lang="php" style="background-color: #9FCFFF">
$a = $db->fetchAssoc($select);
</pre>
<p></br><br />
<b>fetchCol</b><br />
</br></p>
<pre lang="php" style="background-color: #B5DFC1">
while($db->next_record())
{
    $a[] = $db->f('id');
}
</pre>
<p></br></p>
<pre lang="php" style="background-color: #9FCFFF">
$a = $db->fetchCol($select);
</pre>
<p></br><br />
<b>fetchOne</b><br />
</br></p>
<pre lang="php" style="background-color: #B5DFC1">
$db->next_record();
$a = $db->f('id');
</pre>
<p></br></p>
<pre lang="php" style="background-color: #9FCFFF">
$a = $db->fetchOne($select);
</pre>
<p></br><br />
<b>fetchPairs</b><br />
</br></p>
<pre lang="php" style="background-color: #B5DFC1">
while($db->next_record())
{
    $a[$db->f('id')] = $db->f('title');
}
</pre>
<p></br></p>
<pre lang="php" style="background-color: #9FCFFF">
$a = $db->fetchPairs($select);
</pre>
<p></br><br />
<b>fetchRow</b><br />
</br></p>
<pre lang="php" style="background-color: #B5DFC1">
$db->next_record();
$a = array(
		   'id' => $db->f('id'),
		   'title' => $db->f('title')
	      );
</pre>
<p></br></p>
<pre lang="php" style="background-color: #9FCFFF">
$a = $db->fetchRow($select);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dotkernel.com/best-practice/sql-fetch-zend-db/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.dotkernel.com/best-practice/sql-fetch-zend-db/</feedburner:origLink></item>
	</channel>
</rss>
