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
What is the maximum size of a database in mysql?
How do you access a get requests url parameter with php?
Which function is used in php to search a particular value in an array?
Tell me what does the scope of variables means?
Does php 7 support mysql?
What is the function mysql_pconnect() useful for?
How to retrieve the original query string?
How is it possible to remove escape characters from a string?
What is php and how do you use it?
What is the difference between Session and Cookie?
What is the difference server side and browser side validation?
Difference between mysql_connect and mysql_pconnect?
What is difference between php and wordpress?
How can we make a constant in php?
What does a dependant variable mean?