Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Класс для работы с БД
- namespace core;
- use models\Articles;
- class Database
- {
- private $pdo;
- public function __construct()
- {
- $this->pdo = new \PDO(
- 'mysql:host=localhost;dbname=blogforoop;',
- 'root',
- ''
- );
- $this->pdo->exec('SET NAMES UTF8');
- }
- public function query(string $sql, $params = [], string $className = 'stdClass')
- {
- $sth = $this->pdo->prepare($sql);
- $result = $sth->execute($params);
- if (false === $result) {
- return null;
- }
- return $sth->fetchAll(\PDO::FETCH_CLASS, $className);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement