note 91596 added to pdostatement.fetch
| From: | deminy at deminy dot net | Date: | Thu, 18 Jun 2009 17:50:26 +0000 |
| Subject: | note 91596 added to pdostatement.fetch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-157096@lists.php.net to get a copy of this message | ||
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);
}
?>
----
Server IP: 208.69.120.35
Probable Submitter: 208.67.191.194
----
Manual Page -- http://www.php.net/manual/en/pdostatement.fetch.php
Edit -- https://master.php.net/note/edit/91596
Del: integrated -- https://master.php.net/note/delete/91596/integrated
Del: useless -- https://master.php.net/note/delete/91596/useless
Del: bad code -- https://master.php.net/note/delete/91596/bad+code
Del: spam -- https://master.php.net/note/delete/91596/spam
Del: non-english -- https://master.php.net/note/delete/91596/non-english
Del: in docs -- https://master.php.net/note/delete/91596/in+docs
Del: other reasons-- https://master.php.net/note/delete/91596
Reject -- https://master.php.net/note/reject/91596
Search -- https://master.php.net/manage/user-notes.php