Advertisement
Guest User

Untitled

a guest
Oct 19th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. class Db {
  2.  
  3. protected $link;
  4. private $host;
  5. private $user;
  6. private $pass;
  7. private $dbName;
  8.  
  9. public function __construct($host, $user, $pass, $db) {
  10. $this->host = $host;
  11. $this->user = $user;
  12. $this->pass = $pass;
  13. $this->dbName = $db;
  14. $this->connect();
  15. }
  16.  
  17. public function connect() {
  18.  
  19. try
  20. {
  21.  
  22. $this->link = new PDO("mysql:host=" . $this->host .
  23. ";dbname=" . $this->dbName . ";charset=utf8mb4", $this->user, $this->pass );
  24. $this->link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  25. $this->link->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  26.  
  27. } catch (PDOException $exc)
  28. {
  29. $this->setMessage($exc->getMessage());
  30. }
  31. }
  32. }
  33. $db = new Db(HOST, USER,PASS,DB)
  34.  
  35. class Main extends DB {
  36.  
  37. public function __construct() {
  38.  
  39. }
  40. /** App methods bellow*/
  41. }
  42.  
  43. $db2 = new Db(HOST2,USER2,PASS2,DB2);
  44. class User extends DB {
  45.  
  46. public function __construct() {
  47.  
  48. }
  49. /** App methods bellow*/
  50. }
  51.  
  52. class Main extends DB
  53. {
  54.  
  55. public function __construct()
  56. {
  57. parent::__construct();
  58. }
  59. // ...
  60. }
  61.  
  62. class Main extends DB
  63. {
  64.  
  65. public function __construct($host, $user, $pass, $db)
  66. {
  67. parent::__construct($host, $user, $pass, $db);
  68. }
  69. // ...
  70. }
  71.  
  72. class Main
  73. {
  74. protected $db;
  75.  
  76. public function __construct($db)
  77. {
  78. $this->db = $db;
  79. }
  80. // ...
  81. }
  82.  
  83. $mainDb = new Db(HOST, USER,PASS,DB)
  84. $main = new Main($mainDb);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement