Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App;
  4. class Db
  5. {
  6. protected $dbh;
  7.  
  8. public function __construct()
  9. {
  10. $config = (include __DIR__ . '/../config.php')['db'];
  11. $this->dbh = new \PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['dbname'], $config['user'], $config['password']);
  12. }
  13.  
  14. public function query($sql, $class)
  15. {
  16. return $this->dbh->query($sql)->fetchAll(\PDO::FETCH_CLASS, $class);
  17.  
  18. }
  19.  
  20. public function execute(string $query, array $params = [])
  21. {
  22. $request = $this->dbh->prepare($query)->execute($params);
  23. if ($request) {
  24. return true;
  25. }
  26. return false;
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement