title: PDO try-catch usage in functions
body: <p>I'm thinking of using PDO in all of my future webapp. Currently (using what I've learned from SO so far), what I have in my site to handle database connection is a Singleton class like this :</p>
  
  <pre><code>class DB {
  
      private static $instance = NULL;
      private static $dsn      = "mysql:host=localhost;dbname=mydatabase;";
      private static $db_user  = 'root';
      private static $db_pass  = '0O0ooIl1';
  
      private function __construct() 
      {
  
      }
      private function __clone()
      {
  
      }   
      public static function getInstance() {
  
          if (!self::$instance)
          {           
              self::$instance = new PDO(self::$dsn, self::$db_user, self::$db_pass);
              self::$instance-&gt; setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
          }
          return self::$instance;
      }
  }
  </code></pre>
  
  <p>and another file (functions.php) with content-specific functions looking exactly like this one :</p>
  
  <pre><code>function get_recent_activities ()
  {    
      try
      {    
          $db = DB::getInstance();
          // --prepare and execute query here, fetch the result--
          return $my_list_of_recent_activities;
      }
      catch (PDOException $e)
      {
          return "some fail-messages";
      }
  }
  ...
  </code></pre>
  
  <p>meaning that I have to repeat the <code>try .. catch</code> part in all of the functions.</p>
  
  <p>My questions are :</p>
  
  <ol>
  <li>How should I make that more efficient ? (eg. not having to repeat <code>try..catch</code> in all functions, and yet still able to return different "fail-message" on each one)</li>
  <li>Is this already a good practice ? I'm still new at PDO and OOP (still a lot more to learn), so (as of now), I can't really see any disadvantages or things that can be improved in there.</li>
  </ol>
  
  <p>I'm sorry if that seems unclear or too long. Thanks in advance.</p>