title: How to create PDO connection in __construct()?
body: <p>I have one class that is containing three methods. All of those methods need to database, Then I want to create a system for connection to database before everything. Something like this:</p>
  
  <pre><code>Class myclass
  {
      private $db;
  
      public function __construct() {
  
          $db = new PDO("mysql:host = hostname; dbname = database",username, password);
      }
  
      function one()   {/* it needs to database and I will use it like this: */
                           $this-&gt;$db-&gt;prepare("select ...");
                       }
      function two()   {/* also it needs to database */}
      function three() {/* also it needs to database */}
  }
  </code></pre>
  
  <p>Now I want to know (in first) what I did is a standard approach? and (in second) how can I check [if connection was disconnect (in other word connection does not exist) then connect] ?</p>