Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.40 KB | None | 0 0
  1. class DB
  2. {
  3.     public $db;
  4.    
  5.     public function __construct()
  6.     {
  7.         $this->db = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
  8.     }
  9. }
  10.  
  11. class UserDB extends DB
  12. {
  13.     public function getById($id)
  14.     {
  15.         $stmt = $this->db->prepare("SELECT * FROM user WHERE id = :id");
  16.         $stmt->execute(['id' => $id]);
  17.         return $stmt->fetch();
  18.     }
  19. }
  20.  
  21. $userDB = new UserDB();
  22. $user1 = $userDB->getById(101);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement