Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DB extends PDO {
- public $echo_in_log = true;
- public function __construct($dsn, $username = null, $password = null) {
- try {
- parent::__construct($dsn, $username, $password);
- $this->exec("SET NAMES 'utf8'");
- //$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- } catch (PDOException $e) {
- in_log('DB connect error');
- }
- }
- public function ex($sql, array $params = null) {
- $res = null;
- if (!($res = $this->prepare($sql)) ||
- !$res->execute($params)
- ) in_log('DB error. Sql:'.$sql."\nParams".print_r($params, 1));
- return $res;
- }
- protected function in_log($mess) {
- if ($this->echo_in_log) echo 'error';
- in_log($mess);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement