Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Design a class that should always return a single object ?

Answer Posted / amitverma

class DB {
private static $_singleton;
private $_connection;

private function __construct(){
$this->_connection = mysql_connect();
}

public static function getInstance(){
if (is_null (self::$_singleton)) {
self::$_singleton = new DB();
}
return self::$_singleton;
}
}

$db = DB::getInstance();

Is This Answer Correct ?    2 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the maximum size of a database in mysql?

1002


How do you access a get requests url parameter with php?

1014


Which function is used in php to search a particular value in an array?

906


Tell me what does the scope of variables means?

943


Does php 7 support mysql?

1006


What is the function mysql_pconnect() useful for?

955


How to retrieve the original query string?

1076


How is it possible to remove escape characters from a string?

1122


What is php and how do you use it?

999


What is the difference between Session and Cookie?

1064


What is the difference server side and browser side validation?

1005


Difference between mysql_connect and mysql_pconnect?

965


What is difference between php and wordpress?

1152


How can we make a constant in php?

989


What does a dependant variable mean?

1024