Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. <?php
  2.  
  3. // Класс для работы с БД
  4.  
  5. namespace core;
  6.  
  7. use models\Articles;
  8.  
  9. class Database
  10. {
  11. private $pdo;
  12.  
  13. public function __construct()
  14. {
  15. $this->pdo = new \PDO(
  16. 'mysql:host=localhost;dbname=blogforoop;',
  17. 'root',
  18. ''
  19. );
  20. $this->pdo->exec('SET NAMES UTF8');
  21. }
  22.  
  23. public function query(string $sql, $params = [], string $className = 'stdClass')
  24. {
  25. $sth = $this->pdo->prepare($sql);
  26. $result = $sth->execute($params);
  27.  
  28. if (false === $result) {
  29. return null;
  30. }
  31. return $sth->fetchAll(\PDO::FETCH_CLASS, $className);
  32. }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement