note 91596 deleted from pdostatement.fetch by danbrown
| From: | danbrown@php.net | Date: | Thu, 18 Jun 2009 18:15:09 +0000 |
| Subject: | note 91596 deleted from pdostatement.fetch by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-157099@lists.php.net to get a copy of this message | ||
Note Submitter: deminy at deminy dot net
----
From the official documentation, "The return value of this function on success depends on the
fetch type. In all cases, FALSE is returned on failure.". This statement is incomplete.
Actually, in all cases, FALSE is returned on failure or when no data found (at least for PHP 5.2.9).
Run following code on your box to verify it (minor changes on the code may be needed):
<?php
$styles = array(
PDO::FETCH_ASSOC,
PDO::FETCH_BOTH,
PDO::FETCH_BOUND,
PDO::FETCH_CLASS,
PDO::FETCH_INTO,
PDO::FETCH_LAZY,
PDO::FETCH_NUM,
PDO::FETCH_OBJ,
);
$dbh = new PDO('mysql:dbname=testdb;host=localhost', 'test', 'test');
$sth = $dbh->prepare("select * from application where false");
foreach ($styles as $style)
{
$sth->execute();
$result = $sth->fetch($style);
echo $style, ': ';
var_dump($result);
}
?>