Skip to content

Instantly share code, notes, and snippets.

@praswicaksono
Created June 23, 2015 11:21
Show Gist options
  • Select an option

  • Save praswicaksono/9e3b69044d29060f959a to your computer and use it in GitHub Desktop.

Select an option

Save praswicaksono/9e3b69044d29060f959a to your computer and use it in GitHub Desktop.
singleton
class Database
{
/**
* @var \PDO
*/
protected static $conn;
/**
* @return \PDO
*/
public static function getDB()
{
if (! self::$conn instanceof \PDO) {
self::$conn = new \PDO();
}
return self::$conn;
}
}
$conn = Database::getDB();
$conn->query("blo bla bla");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment