<?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>Databases &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/databases/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>Fetching Rows With Zend_Db fetch()</title>
		<link>/2010/08/05/fetching-rows-with-zend_db-fetch/</link>
		<comments>/2010/08/05/fetching-rows-with-zend_db-fetch/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 14:14:51 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Data management]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[select]]></category>
		<category><![CDATA[SQL keywords]]></category>
		<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">/?p=1881</guid>
		<description><![CDATA[Fetching the Entire Row Set What is really handy in Zend Framework is that you can fetch the entire row set with the fetchAll() method. It comes with some parameters that you can use for limiting the result or ordering, but in general you can use it without specifying parameters. Let say this is the &#8230; <a href="/2010/08/05/fetching-rows-with-zend_db-fetch/" class="more-link">Continue reading <span class="screen-reader-text">Fetching Rows With Zend_Db fetch()</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/08/17/php-fetch-get-as-string-with-http_build_query/" rel="bookmark" title="PHP: Fetch $_GET as String with http_build_query()">PHP: Fetch $_GET as String with http_build_query() </a></li>
<li><a href="/2010/08/27/php-what-is-more-powerful-than-list/" rel="bookmark" title="PHP: What is More Powerful Than list()">PHP: What is More Powerful Than list() </a></li>
<li><a href="/2012/02/09/how-to-dump-the-generated-zend_db-sql-query/" rel="bookmark" title="How to Dump the Generated Zend_Db SQL Query">How to Dump the Generated Zend_Db SQL Query </a></li>
<li><a href="/2010/04/21/setting-a-zend-framework-_redirect-referer/" rel="bookmark" title="Setting a Zend Framework _redirect Referer">Setting a Zend Framework _redirect Referer </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Fetching the Entire Row Set</h2>
<p><a href="/wp-content/uploads/2010/08/rows.jpg"><img class="aligncenter size-full wp-image-1891" title="rows" src="/wp-content/uploads/2010/08/rows.jpg" alt="Rows" width="430" height="262" srcset="/wp-content/uploads/2010/08/rows.jpg 430w, /wp-content/uploads/2010/08/rows-300x182.jpg 300w" sizes="(max-width: 430px) 100vw, 430px" /></a></p>
<p>What is really handy in Zend Framework is that you can fetch the entire row set with the fetchAll() method. It comes with some parameters that you can use for limiting the result or ordering, but in general you can use it without specifying parameters. Let say this is the model:</p>
<pre lang="php">
<?php
class User extends Zend_Db_Table
{
		
	public function listAll()
	{
		$query = "SELECT * FROM user";
	
		// exec query
		$rs = $this->getAdapter()->query($query);
	
		return $rs->fetchAll();
		
	}
	
}
</pre>
<p>You can simply return the row set with the fetchAll() method as described in the example, but what if you have to loop through the rows and to modify somehow the values?</p>
<h2>Fetching a Row</h2>
<p>By simply change the code like so:</p>
<pre lang="php">
class User extends Zend_Db_Table
{
		
	public function listAll()
	{
		$query = "SELECT * FROM user";
	
		// exec query
		$rs = $this->getAdapter()->query($query);
	
		// fetch
		$list = array();
		while ($row = $rs->fetch()) {
			// removing the password column value
			$row['password'] = '';
			
		    $list[] = $row;
		}
	
		return $list;
	}
}
</pre>
<p>you can modify the rows and you&#8217;ll have the same result.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/08/17/php-fetch-get-as-string-with-http_build_query/" rel="bookmark" title="PHP: Fetch $_GET as String with http_build_query()">PHP: Fetch $_GET as String with http_build_query() </a></li>
<li><a href="/2010/08/27/php-what-is-more-powerful-than-list/" rel="bookmark" title="PHP: What is More Powerful Than list()">PHP: What is More Powerful Than list() </a></li>
<li><a href="/2012/02/09/how-to-dump-the-generated-zend_db-sql-query/" rel="bookmark" title="How to Dump the Generated Zend_Db SQL Query">How to Dump the Generated Zend_Db SQL Query </a></li>
<li><a href="/2010/04/21/setting-a-zend-framework-_redirect-referer/" rel="bookmark" title="Setting a Zend Framework _redirect Referer">Setting a Zend Framework _redirect Referer </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/08/05/fetching-rows-with-zend_db-fetch/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Which Model Should Contain That Method?</title>
		<link>/2010/07/28/which-model-should-contain-that-method/</link>
		<comments>/2010/07/28/which-model-should-contain-that-method/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 15:07:41 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[Business/Finance]]></category>
		<category><![CDATA[Computer science]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Data management]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Database management systems]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[From]]></category>
		<category><![CDATA[Human Interest]]></category>
		<category><![CDATA[IBM software]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL keywords]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">/?p=1866</guid>
		<description><![CDATA[Let&#8217;s say you have two models &#8211; each one modeling a database table &#8211; Users &#38; Article. Here there&#8217;s nothing to deal with Zend Framwork, but you can think of them as typical models in a ZF application. What happens if you have to write a getUserArticles method? Where would you put it? Whether this &#8230; <a href="/2010/07/28/which-model-should-contain-that-method/" class="more-link">Continue reading <span class="screen-reader-text">Which Model Should Contain That Method?</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/07/12/mvc-in-practice-designing-models/" rel="bookmark" title="MVC in Practice: Designing Models">MVC in Practice: Designing Models </a></li>
<li><a href="/2010/07/19/zend-framework-cache-database-table-schemes/" rel="bookmark" title="Zend Framework: Cache Database Table Schemes">Zend Framework: Cache Database Table Schemes </a></li>
<li><a href="/2010/08/05/fetching-rows-with-zend_db-fetch/" rel="bookmark" title="Fetching Rows With Zend_Db fetch()">Fetching Rows With Zend_Db fetch() </a></li>
<li><a href="/2010/04/26/mysql-expressions-in-zend-framework/" rel="bookmark" title="MySQL Expressions in Zend Framework">MySQL Expressions in Zend Framework </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Let&#8217;s say you have two models &#8211; each one modeling a database table &#8211; <strong>Users</strong> &amp; <strong>Article</strong>. Here there&#8217;s nothing to deal with Zend Framwork, but you can think of them as typical models in a ZF application.</p>
<p>What happens if you have to write a getUserArticles method? Where would you put it? Whether this will be the User model or the Article model?<a href="/wp-content/uploads/2010/07/question.jpg"><img class="aligncenter size-full  wp-image-1875" title="question" src="/wp-content/uploads/2010/07/question.jpg" alt="Where?" width="430" height="231" srcset="/wp-content/uploads/2010/07/question.jpg 430w, /wp-content/uploads/2010/07/question-300x161.jpg 300w" sizes="(max-width: 430px) 100vw, 430px" /></a></p>
<p>Although technically you can put it in both models my advice is to look at the SQL query. If the FROM clause is containing the user table &#8211; than put the method in the User model, but here you&#8217;d have something like:</p>
<pre lang="sql">
SELECT * FROM Article WHERE user_id = 1
</pre>
<p>I&#8217;d prefer to place it in the Article model!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/07/12/mvc-in-practice-designing-models/" rel="bookmark" title="MVC in Practice: Designing Models">MVC in Practice: Designing Models </a></li>
<li><a href="/2010/07/19/zend-framework-cache-database-table-schemes/" rel="bookmark" title="Zend Framework: Cache Database Table Schemes">Zend Framework: Cache Database Table Schemes </a></li>
<li><a href="/2010/08/05/fetching-rows-with-zend_db-fetch/" rel="bookmark" title="Fetching Rows With Zend_Db fetch()">Fetching Rows With Zend_Db fetch() </a></li>
<li><a href="/2010/04/26/mysql-expressions-in-zend-framework/" rel="bookmark" title="MySQL Expressions in Zend Framework">MySQL Expressions in Zend Framework </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/07/28/which-model-should-contain-that-method/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
