title: Passing a PDO connection as a session var
body: <p>So in the interest of not repeating myself, I only want to create one PDO connection and pass it between pages using a session var.  But when I setup my PDO connection and set the session var, the var is coming back as not set on my next page?</p>
  
  <p>This is the code on my first page:</p>
  
  <pre><code>session_start();
  try
  {
      $db = new PDO("mysql:host=".$dbHostname.";dbname=".$dbDatabase, $dbUsername, $dbPassword);
      $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  }
  catch(PDOException $e)
  {
      echo "It seems there was an error.  Please refresh your browser and try again. ".$e-&gt;getMessage();
  }
  
  $_SESSION['db'] = $db;
  </code></pre>
  
  <p>Then this test code on my next page comes back as not set.</p>
  
  <pre><code>session_start();
  $db = $_SESSION['db'];
  
      if(isset($db))echo "set";
      else echo "not set";
  </code></pre>
  
  <p>Any ideas??</p>
  
  <p>The connection is fine because if I call a function from the first page and pass along $db as a parameter, the function works without any problems.  So why would storing the database var as a session not work?  Thank you for any help.</p>