Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Database not selected php 5.3
- $host = 'localhost'
- $user = 'root'
- $password = ''
- $db = 'mydb'
- class Conf{
- private $_userdb;
- private $_passdb;
- private $_hostdb;
- private $_db;
- static $_instance;
- private function __construct(){
- require 'config.php';
- $this->_userdb=$user;
- $this->_passdb=$password;
- $this->_hostdb=$host;
- $this->_db=$db;
- }
- private function __clone(){ }
- public static function getInstance(){
- if (!(self::$_instance instanceof self)){
- self::$_instance=new self();
- }
- return self::$_instance;
- }
- public function getUserDB(){
- $var=$this->_userdb;
- return $var;
- }
- public function getHostDB(){
- $var=$this->_hostdb;
- return $var;
- }
- public function getPassDB(){
- $var=$this->_passdb;
- return $var;
- }
- public function getDB(){
- $var=$this->_db;
- return $var;
- }
- }
- class Db {
- private $server;
- private $user;
- private $password;
- private $data_base;
- private $link;
- private $result;
- static $_instance;
- private function __construct() {
- $this->setConnection();
- $this->connect();
- $this->result = null;
- }
- private function setConnection() {
- $conf = Conf::getInstance();
- $this->server = $conf->getHostDB();
- $this->data_base = $conf->getDB();
- $this->user = $conf->getUserDB();
- $this->password = $conf->getPassDB();
- }
- private function __clone(){ }
- public static function getInstance() {
- if (!(self::$_instance instanceof self)){
- self::$_instance=new self();
- } return self::$_instance;
- }
- private function connect() {
- $link=mysql_connect($this->server, $this->user, $this->password);
- if ($link){
- mysql_select_db($this->data_base,$link);
- }
- if (!$link){
- die('Can not connect');
- }else{
- $this->link = $link;
- }
- }
- }
Add Comment
Please, Sign In to add comment