Guest User

Untitled

a guest
Aug 2nd, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. Database not selected php 5.3
  2. $host = 'localhost'
  3. $user = 'root'
  4. $password = ''
  5. $db = 'mydb'
  6.  
  7. class Conf{
  8.  
  9. private $_userdb;
  10. private $_passdb;
  11. private $_hostdb;
  12. private $_db;
  13. static $_instance;
  14.  
  15. private function __construct(){
  16. require 'config.php';
  17. $this->_userdb=$user;
  18. $this->_passdb=$password;
  19. $this->_hostdb=$host;
  20. $this->_db=$db;
  21. }
  22.  
  23. private function __clone(){ }
  24.  
  25. public static function getInstance(){
  26. if (!(self::$_instance instanceof self)){
  27. self::$_instance=new self();
  28. }
  29. return self::$_instance;
  30. }
  31.  
  32. public function getUserDB(){
  33. $var=$this->_userdb;
  34. return $var;
  35. }
  36.  
  37. public function getHostDB(){
  38. $var=$this->_hostdb;
  39. return $var;
  40. }
  41. public function getPassDB(){
  42. $var=$this->_passdb;
  43. return $var;
  44. }
  45.  
  46. public function getDB(){
  47. $var=$this->_db;
  48. return $var;
  49. }
  50. }
  51.  
  52. class Db {
  53. private $server;
  54. private $user;
  55. private $password;
  56. private $data_base;
  57. private $link;
  58. private $result;
  59. static $_instance;
  60.  
  61.  
  62. private function __construct() {
  63. $this->setConnection();
  64. $this->connect();
  65. $this->result = null;
  66. }
  67.  
  68. private function setConnection() {
  69. $conf = Conf::getInstance();
  70. $this->server = $conf->getHostDB();
  71. $this->data_base = $conf->getDB();
  72. $this->user = $conf->getUserDB();
  73. $this->password = $conf->getPassDB();
  74. }
  75.  
  76. private function __clone(){ }
  77.  
  78. public static function getInstance() {
  79.  
  80. if (!(self::$_instance instanceof self)){
  81. self::$_instance=new self();
  82. } return self::$_instance;
  83.  
  84. }
  85.  
  86.  
  87. private function connect() {
  88.  
  89. $link=mysql_connect($this->server, $this->user, $this->password);
  90. if ($link){
  91. mysql_select_db($this->data_base,$link);
  92. }
  93. if (!$link){
  94. die('Can not connect');
  95. }else{
  96. $this->link = $link;
  97. }
  98.  
  99. }
  100. }
Add Comment
Please, Sign In to add comment