Created
February 6, 2017 18:24
-
-
Save laerciobernardo/3b3fbd1c4357822695a510e65b72c92f to your computer and use it in GitHub Desktop.
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
$stmt = $dbh->prepare(' | |
SELECT | |
* | |
FROM | |
table | |
ORDER BY | |
name | |
LIMIT | |
:limit | |
OFFSET | |
:offset | |
'); | |
// Bind the query params | |
$stmt->bindParam(':limit', $limit, PDO::PARAM_INT); | |
$stmt->bindParam(':offset', $offset, PDO::PARAM_INT); | |
$stmt->execute(); | |
// Do we have any results? | |
if ($stmt->rowCount() > 0) { | |
// Define how we want to fetch the results | |
$stmt->setFetchMode(PDO::FETCH_ASSOC); | |
$iterator = new IteratorIterator($stmt); | |
// Display the results | |
foreach ($iterator as $row) { | |
echo '<p>', $row['name'], '</p>'; | |
} | |
} else { | |
echo '<p>No results could be displayed.</p>'; | |
} | |
} catch (Exception $e) { | |
echo '<p>', $e->getMessage(), '</p>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment