title: Singleton alternative for PHP PDO
body: <p>This is my class that I'm using to connect to my <code>MySQL</code> database.
  As you can see I'm using the <code>Singleton Pattern</code> but almost every post says it is a very bad pattern. What is the best approach to create a database connection class? Is there a better pattern?</p>
  
  <pre><code>class DB extends PDO {
  
      function __construct() {
          try {
              parent::__construct('mysql:host=' . 'localhost' . ';dbname=' . 'kida', 'root', 'root', array(PDO::MYSQL_ATTR_INIT_COMMAND =&gt; "SET NAMES 'utf8'");
              parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
          } catch(PDOException $e) {
              echo $e-&gt;getMessage();
          }
      }
  
      public static function get_instance() {
          static $instance = false;
          if(!$instance) $instance = new self;
          return $instance; //returns pdo object.
       }
  }
  </code></pre>