title: PDO Connection and abstract class
body: <p>I am using abstract class with PDO. I want to know if it is necessary to null the <code>$conn</code> variable every time, or if it does so itself when the scripts ends?</p>
  
  <p>Can you also tell me, with this type of structure, what would be the best way to nullify <code>$conn</code>?</p>
  
  <pre><code>abstract class DB_Connection
  {
      protected static $tbl_admin = "prof_admin";
      //protected static $tbl_admin = "prof_admin";
  
      protected static function obj_db()
      {
          $servername = "localhost";
          $username = "root";
          $password = "";
          $dbname = "salmanshahid";
          $conn = null;
  
          try 
          {
              $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
              // set the PDO error mode to exception
              $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
              return $conn;
          }
          catch(PDOException $e)
          {
              echo $sql . "&lt;br&gt;" . $e-&gt;getMessage();
          } 
      }
      protected static function select($query)
      {
          try 
          {
              $conn = self::obj_db();
              $stmt = $conn-&gt;prepare($query);
              $stmt-&gt;execute();
  
              // set the resulting array to associative
              $stmt-&gt;setFetchMode(PDO::FETCH_ASSOC); 
              return $stmt-&gt;fetchAll();
          }
          catch(PDOException $e) 
          {
              throw new Exception("Error In SELECT STATMENT: " . $e-&gt;getMessage());
          }
      }
      protected static function insert($query)
      {
          try 
          {
              $conn = self::obj_db();
              $stmt = $conn-&gt;prepare($query);
              $stmt-&gt;execute();
          }
          catch(PDOException $e) 
          {
              throw new Exception("Error In INSERT STATMENT: " . $e-&gt;getMessage());
          }
      }
  
  }
  </code></pre>