Guest User

Untitled

a guest
Jan 20th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <?php
  2. class Todo
  3. {
  4. private $description;
  5. private $completed;
  6. private $due;
  7. public function __construct($description, $completed, $due)
  8. {
  9. $this->description = $description;
  10. $this->completed = $completed;
  11. $this->due = $due;
  12. }
  13. public function setDescription($description)
  14. {
  15. $this->description = $description;
  16. }
  17. public function setCompleted($completed)
  18. {
  19. $this->completed = $completed;
  20. }
  21. public function setDue($due)
  22. {
  23. $this->due = $due;
  24. }
  25. }
  26. $host = "127.0.0.1";
  27. $port = "3306";
  28. $username = "root";
  29. $password = "";
  30. //By default, wrap a PDO inside a try-catch statement!
  31. try {
  32. $pdo = new PDO("mysql:host={$host};port={$port};dbname=test", $username, $password);
  33. echo "Connected successfully";
  34. } catch (PDOException $e) {
  35. die("Connection failed: " . $e->getMessage());
  36. }
  37. //Prepare statement (not executed yet)
  38. $statement = $pdo->prepare("SELECT * FROM todos");
  39. //Execute it
  40. $statement->execute();
  41. echo "\n\PDO:\n\n";
  42. //Store all data inside an object
  43. //Works completely fine on private props!
  44. $todos = $statement->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE, "Todo", array('val1', 'val2', 'val3'));
  45. var_dump($todos);
Add Comment
Please, Sign In to add comment