Last active
August 29, 2015 14:27
-
-
Save terrymun/9c6dece0271e072e561b to your computer and use it in GitHub Desktop.
Count the number of rows returned
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Assuming that database connection is already open | |
// Prepare statement | |
$stmt = $db->prepare("SELECT user, email, country FROM users WHERE id > 1000"); | |
$stmt->execute(); | |
// Get results | |
if($stmt->rowCount() > 0) { | |
// One or more rows returned, start iteration through set | |
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { | |
// Do something for each row | |
} | |
} else { | |
// No rows returned | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment