alexandrheathen

Db class

Feb 2nd, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.45 KB | None | 0 0
  1. <?php
  2.  
  3. class Db {
  4.     public static function getConnection () {
  5.         $paramsPath = ROOT . '/config/db_params.php';
  6.         $params     = include( $paramsPath );
  7.  
  8.         $dsn = "mysql:host={$params['host']};dbname={$params['db']};charset=utf8";
  9.         $opt = [
  10.             PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
  11.             PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
  12.         ];
  13.         $db  = new PDO($dsn, $params['user'], $params['password'], $opt);
  14.  
  15.         return $db;
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment