note 77146 added to function.PDOStatement-fetch
| From: | BaBna at osu1 dot php dot net | Date: | Thu, 16 Aug 2007 19:52:26 +0000 |
| Subject: | note 77146 added to function.PDOStatement-fetch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129544@lists.php.net to get a copy of this message | ||
When you do a SELECT query for one row, and want to check if it's there, you don't need to
count the fetchAll() result, you can just check if $result->fetch() is true:
<?php
$bbnq = sprintf("SELECT login
FROM users
WHERE id = %u",27);
try
{ $req = $db_bbn->query($bbnq); }
catch (Exception $e)
{ bbnf_pdo_error($e,__FILE__,__LINE__); }
if ( $r = $req->fetch() )
{ echo "This query has a row result"; }
else
{ echo "This query has an empty result"; }
?>
----
Server IP: 193.95.141.37
Probable Submitter: 87.198.27.117
----
Manual Page -- http://www.php.net/manual/en/function.PDOStatement-fetch.php
Edit -- https://master.php.net/note/edit/77146
Del: integrated -- https://master.php.net/note/delete/77146/integrated
Del: useless -- https://master.php.net/note/delete/77146/useless
Del: bad code -- https://master.php.net/note/delete/77146/bad+code
Del: spam -- https://master.php.net/note/delete/77146/spam
Del: non-english -- https://master.php.net/note/delete/77146/non-english
Del: in docs -- https://master.php.net/note/delete/77146/in+docs
Del: other reasons-- https://master.php.net/note/delete/77146
Reject -- https://master.php.net/note/reject/77146
Search -- https://master.php.net/manage/user-notes.php