Guest User

Untitled

a guest
Feb 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. try {
  2. $query = "SELECT CONCAT(firstName, lastName) AS name ";
  3. $query .= "FROM people AS p ";
  4. $query .= "WHERE p.age=:age ";
  5. $query .= "ORDER BY name DESC ";
  6.  
  7. $statement = $pdoRef->prepare($query);
  8.  
  9. $statement->bindParam(":age", $age, PDO::PARAM_INT);
  10.  
  11. if (!$statement->execute())
  12. throw new Exception("Statement did not execute");
  13.  
  14. $result = $statement->fetchAll();
  15.  
  16. if (count($result) === 0)
  17. throw new Exception("0 Results");
  18.  
  19. foreach ($result as $person) {
  20. //
  21. }
  22.  
  23. } catch (PDOException $ex) {
  24. // do something with $ex->getMessage();
  25. } catch (Exception $ex) {
  26. // do something with $ex->getMessage();
  27. }
Add Comment
Please, Sign In to add comment