Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Todo
- {
- private $description;
- private $completed;
- private $due;
- public function __construct($description, $completed, $due)
- {
- $this->description = $description;
- $this->completed = $completed;
- $this->due = $due;
- }
- public function setDescription($description)
- {
- $this->description = $description;
- }
- public function setCompleted($completed)
- {
- $this->completed = $completed;
- }
- public function setDue($due)
- {
- $this->due = $due;
- }
- }
- $host = "127.0.0.1";
- $port = "3306";
- $username = "root";
- $password = "";
- //By default, wrap a PDO inside a try-catch statement!
- try {
- $pdo = new PDO("mysql:host={$host};port={$port};dbname=test", $username, $password);
- echo "Connected successfully";
- } catch (PDOException $e) {
- die("Connection failed: " . $e->getMessage());
- }
- //Prepare statement (not executed yet)
- $statement = $pdo->prepare("SELECT * FROM todos");
- //Execute it
- $statement->execute();
- echo "\n\PDO:\n\n";
- //Store all data inside an object
- //Works completely fine on private props!
- $todos = $statement->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE, "Todo", array('val1', 'val2', 'val3'));
- var_dump($todos);
Add Comment
Please, Sign In to add comment