note 72609 modified in pdostatement-fetchcolumn by danbrown
| From: | danbrown@php.net | Date: | Tue, 09 Dec 2008 04:54:19 +0000 |
| Subject: | note 72609 modified in pdostatement-fetchcolumn by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147932@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/pdostatement-fetchcolumn.php