note 72609 modified in function.pdostatement-fetchcolumn by danbrown

From: Date: Fri, 28 Nov 2008 21:43:45 +0000
Subject: note 72609 modified in function.pdostatement-fetchcolumn by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147260@lists.php.net to get a copy of this message
This is an excellent method for returning a column count. For example: <?php $db = new PDO('mysql:host=localhost;dbname=pictures','user','password'); $pics = $db->query('SELECT COUNT(id) FROM pics'); $this->totalpics = $pics->fetchColumn(); $db = null; ?> In my case $pics->fetchColumn() returns 641 because that is how many pictures I have in my db. --was-- This is an excellent method for returning a column count. For example: <?php $db = new PDO('mysql:host=localhost;dbname=pictures','user','password'); $pics = $db->query('SELECT COUNT(id) FROM pics'); $this->totalpics = $pics->fetchColumn(); $db = null; ?> In my case $pics->fetchColumn() returns 641 because that is how many pictures I have in my db. http://php.net/manual/en/function.pdostatement-fetchcolumn.php

« previous php.notes (#147260) next »