Current Path : /data/web/virtuals/51568/virtual/www/subdom/agenda.1/php/ |
Current File : /data/web/virtuals/51568/virtual/www/subdom/agenda.1/php/DB.php |
<?php class DB { // private $dsn = 'mysql:host=wm39.wedos.net;dbname=d51568_douc'; // private $user = 'w51568_douc'; // private $password = 'XQjPE8Ud'; private $dsn = 'mysql:host=md203.wedos.net;dbname=d51568_agenda'; private $user = 'w51568_agenda'; private $password = 'GUqCjPwB'; private $options = [ PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8", PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_EMULATE_PREPARES => false, ]; private $pdo; private $params = []; public function __construct() { $this->params = [$this->dsn, $this->user, $this->password]; $this->connect(); } public function connect() { if ($this->pdo) { return; } try { $this->pdo = new PDO($this->params[0], $this->params[1], $this->params[2], $this->options); $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { throw $e; } } public function query($sql, ...$params) { try { $navrat = $this->pdo->prepare($sql); $navrat->execute($params); return $navrat; } catch (PDOException $e) { throw new Exception('Chyba při provádění DB příkazu. '.$e); } } public function fetchOne($sql, ...$params) { return $this->query($sql, ...$params)->fetch(); } public function fetchOneAsoc($sql, ...$params) { return $this->query($sql, ...$params)->fetch(PDO::FETCH_ASSOC); } public function fetchAll($sql, ...$params) { return $this->query($sql, ...$params)->fetchAll(); } public function lastInsertId($sequence = null) { return $this->pdo->lastInsertId($sequence); } /* public function call_sp($customerNumber) { try { $pdo = new PDO("mysql:host=localhost;dbname=classicmodels", 'root', ''); // execute the stored procedure $sql = 'CALL get_order_by_cust(:no,@shipped,@canceled,@resolved,@disputed)'; $stmt = $pdo->prepare($sql); $stmt->bindParam(':no', $customerNumber, PDO::PARAM_INT); $stmt->execute(); $stmt->closeCursor(); // execute the second query to get values from OUT parameter $r = $pdo->query("SELECT @shipped,@canceled,@resolved,@disputed") ->fetch(PDO::FETCH_ASSOC); if ($r) { printf('Shipped: %d, Canceled: %d, Resolved: %d, Disputed: %d', $r['@shipped'], $r['@canceled'], $r['@resolved'], $r['@disputed']); } } catch (PDOException $pe) { die("Error occurred:" . $pe->getMessage()); } } */ }