Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. <?php
  2. class DBC {
  3.  
  4. public $isConn;
  5. protected $datab;
  6.  
  7. public function __construct($username = "", $password = "", $host = "", $dbname = "", $options = []) {
  8. $this->isConn = true;
  9. try {
  10. $this->datab = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
  11. $this->datab->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  12. $this->datab->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
  13. } catch (PDOException $e) {
  14. throw new Exception($e->getMessage());
  15. }
  16. }
  17.  
  18. public function Disconnect() {
  19. $this->datab = null;
  20. $this->isConn = false;
  21. }
  22.  
  23. public function get($query, $params = []) {
  24. try {
  25. $this->datab->quote($query);
  26. $stmt = $this->datab->prepare($query);
  27. $stmt->execute($params);
  28. return $stmt->fetchALL();
  29. } catch (PDOException $e) {
  30. throw new Exception($e->getMessage());
  31. }
  32. }
  33.  
  34. public function set($query, $params = []) {
  35. try {
  36. $this->datab->quote($query);
  37. $stmt = $this->datab->prepare($query);
  38. $stmt->execute($params);
  39. return true;
  40. } catch (PDOException $e) {
  41. throw new Exception($e->getMessage());
  42. }
  43. }
  44.  
  45. }
  46.  
  47. $dbc = new DBC();
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement