title: PHP - Good design pattern for static database connection class
body: <p>I have a "static" class which connects to database and has various functions. The current base layout is as follows:</p>
  
  <pre><code>class DB {
  
      private static $con;
  
      private function __construct() {};
  
      private static function init() {
          if(is_null(self::$con) {
              // Initialize database connection
          }
      }
  
      public static someMethod1() {
          self::init();
          // Do stuff
      }
  
      public static someMethod2() {
          self::init();
          // Do stuff
      }
  
      public static someMethod2() {
          self::init();
          // Do stuff
      }
  }
  </code></pre>
  
  <p>My intention is to be easily be able to call these methods as: <code>DB::someMethod1()</code>. However, as you can see, I am having to cehck for initialization at every method beginning. Is this a good coding practice? Is there a better design pattern available? Initially I thought of builder pattern but that doesn't really fit here in my opinion.</p>