Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. class DB extends PDO {
  2.     public $echo_in_log = true;
  3.    
  4.     public function __construct($dsn, $username = null, $password = null) {
  5.         try {
  6.             parent::__construct($dsn, $username, $password);
  7.             $this->exec("SET NAMES 'utf8'");
  8.             //$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  9.         } catch (PDOException $e) {
  10.             in_log('DB connect error');
  11.         }
  12.     }
  13.    
  14.     public function ex($sql, array $params = null) {
  15.         $res = null;
  16.         if (!($res = $this->prepare($sql)) ||
  17.             !$res->execute($params)
  18.         ) in_log('DB error. Sql:'.$sql."\nParams".print_r($params, 1));
  19.         return $res;
  20.     }
  21.    
  22.     protected function in_log($mess) {
  23.         if ($this->echo_in_log) echo 'error';
  24.         in_log($mess);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement