note 118456 added to pdostatement.rowcount
| From: | lsrzjatfacebook | Date: | Wed, 09 Dec 2015 14:03:28 +0000 |
| Subject: | note 118456 added to pdostatement.rowcount | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204315@lists.php.net to get a copy of this message | ||
Well, I woundn't do as suggested querying twice the database to get the count and then get the
data I want. It would be simpler and would give better performance to query once and retrieve both,
record count and the data itself
<?php
$sql = "SELECT * FROM fruit WHERE calories > :calories";
$sth = $conn->prepare($sql);
$sth->bindParam(':calories', 100, PDO::PARAM_INT);
$res = $sth->execute();
if ($res) {
$record = $sth->fetchAll();
/* Check the number of rows that match the SELECT statement */
if (count($record) > 0) {
foreach ($record as $row) {
print "Name: " . $row['NAME'] . "\n";
}
}
/* No rows matched -- do something else */
else {
print "No rows matched the query.";
}
}
$conn = null;
?>
----
Server IP: 72.52.91.14
Probable Submitter: 177.97.205.239
----
Manual Page -- http://php.net/manual/en/pdostatement.rowcount.php
Edit -- https://master.php.net/note/edit/118456
Del: integrated -- https://master.php.net/note/delete/118456/integrated
Del: useless -- https://master.php.net/note/delete/118456/useless
Del: bad code -- https://master.php.net/note/delete/118456/bad+code
Del: spam -- https://master.php.net/note/delete/118456/spam
Del: non-english -- https://master.php.net/note/delete/118456/non-english
Del: in docs -- https://master.php.net/note/delete/118456/in+docs
Del: other reasons-- https://master.php.net/note/delete/118456
Reject -- https://master.php.net/note/reject/118456
Search -- https://master.php.net/manage/user-notes.php