<?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>Young Dutch Design &#187; Webdesign</title>
	<atom:link href="http://youngdutchdesign.com/tag/webdesign/feed" rel="self" type="application/rss+xml" />
	<link>http://youngdutchdesign.com</link>
	<description>Young Dutch Design is a new platform for young designers with frequently new added postings about productdesign, webdesign and other related subjects.</description>
	<lastBuildDate>Tue, 14 Jun 2011 20:25:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>mysql_num_rows with PDO</title>
		<link>http://youngdutchdesign.com/pdo-numrows</link>
		<comments>http://youngdutchdesign.com/pdo-numrows#comments</comments>
		<pubDate>Fri, 06 Mar 2009 09:12:37 +0000</pubDate>
		<dc:creator>Crispijn</dc:creator>
				<category><![CDATA[Webdesign]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://youngdutchdesign.com/?p=643</guid>
		<description><![CDATA[I&#8217;ve switched a couple of years ago to PDO to manage all the database actions. PDO (PHP Data Objects) is an object orientated extension that requires at least php 5.1. In many cases software improves and is often more easy to use. But why did the php development-team  forgot to write a similar function like [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve switched a couple of years ago to PDO to manage all the database actions. PDO (PHP Data Objects) is an object orientated extension that requires at least php 5.1. In many cases software improves and is often more easy to use. But why did the php development-team  forgot to write a similar function like <a href="http://php.net/mysql_num_rows" target="_blank">mysql_num_rows</a>?</p>
<p>In this case you always need to run an extra query to retrieve the total records. See the examples below.</p>
<p><span id="more-643"></span></p>
<h2>Old style</h2>
<pre class="php">$sql = "SELECT id, name FROM table WHERE cat = 1";
$res = mysql_query($sql);
$count = mysql_num_rows($res);</pre>
<p>Read more about the <a href="http://youngdutchdesign.com/minimum-error-handling-on-mysql-with-php">basic error handler</a> in a previous article.</p>
<h2>PDO style</h2>
<pre class="php">try{
	$sql = "SELECT COUNT(id), name FROM table WHERE cat = 1";
	$res = $this-&gt;db-&gt;prepare($sql);
	$res-&gt;execute();

	//count the rows
	$count = $res-&gt;fetchColumn();
}catch(PDOException $e){
	//Basic error handler
	return $e-&gt;getMessage();
	return $sql;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://youngdutchdesign.com/pdo-numrows/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
