Advertisement
Guest User

Untitled

a guest
Mar 11th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. <?php
  2. $user = 'user';
  3. $pass = 'pass';
  4.  
  5. try {
  6. $db = new PDO('mysql:host=localhost;dbname=dbname', $user, $pass);
  7. $db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  8. } catch(PDOException $e) {
  9. echo '<h1>' . $e->getMessage() . '</h1>';
  10. }
  11. ?>
  12.  
  13. function getSnippets($snippetID, $page) {
  14. global $db;
  15. try {
  16. $SQL = $db->prepare('SELECT * FROM snippets WHERE id=:snippetID ORDER BY id LIMIT 10, :page');
  17. $SQL->setFetchMode(PDO::FETCH_ASSOC); // Set mode to fetch associative array
  18. $SQL->execute(array(
  19. ':snippetID' => $snippetID,
  20. ':page' => $page
  21. ));
  22. $result = $SQL->fetchALL(PDO::FETCH_ASSOC);
  23. return $result;
  24. } catch (PDOException $e) {
  25. echo $e->getMessage();
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement