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

Explain how we can retrieve the data in the result set of mysql using php?

974


what the new feature add in php 7.2?

966


What does the arrow mean in php?

998


Which php function will attach one file to another?

976


Name and explain five of the PHP error constants?

942


How to redirect https to http url and vice versa in .htaccess?

970


Tell me are parent constructors called implicitly inside a class constructor?

937


Tell me in php, objects are they passed by value or by reference?

960


What is print_r?

887


How check field is empty or not in php?

1032


What is the use of htmlspecialchars in php?

988


What is the use of stripslashes in php?

975


What is a lambda function in php?

1084


What is a http session?

940


What are the features of php?

1015