Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. // Execute returns false, no exception thrown
  2. $so = $rh->pdo->prepare("SELECT * FROM config");
  3. if($so->execute(['Test']) === FALSE) echo '1. False returned <br />';
  4.  
  5. // Execute does not return false, no exception thrown
  6. $so = $rh->pdo->prepare("SELECT * FROM config");
  7. if($so->bindValue(1, 'Test') === FALSE) echo '2. Binding failed <br />';
  8. if($so->execute() === FALSE) echo '2. False not returned <br />';
  9.  
  10. // Execute returns false, no exception thrown
  11. $so = $rh->pdo->prepare("SELECT * FROM config WHERE webmaster_name = ?");
  12. if($so->execute(['Test', 'Wee']) === FALSE) echo '3. False returned <br />';
  13.  
  14. // Execute does not return false, no exception thrown
  15. $so = $rh->pdo->prepare("SELECT * FROM config WHERE webmaster_name = ?");
  16. $so->bindValue(1, 'Test');
  17. if($so->bindValue(2, 'Wee') === FALSE) echo '4. Binding failed <br />';
  18. if($so->execute() === FALSE) echo '4. False not returned <br />';
  19.  
  20. Outputs:
  21. 1. False returned
  22. 2. Binding failed
  23. 3. False returned
  24. 4. Binding failed
  25.  
  26. $user_info = $rh->pdo->query("SELECT * FROM users WHERE user_id = 1")->fetch();
  27.  
  28. // vs
  29.  
  30. $so = $rh->pdo->query("SELECT * FROM users WHERE user_id = 1");
  31. if($so === FALSE) // Throw an exception
  32. $user_info = $so->fetch();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement