title: Reusing variables when working with PDO
body: <p>I have to pull data from at least 3 databases, is there anything wrong with reusing my PDO objects?</p>
  
  <pre><code>$dbh = new PDO('mysql:host=' . $host . ';dbname=' . $db_name, $user, $password);
  $sth = $dbh-&gt;prepare($query1);
  
  // do something
  
  $dbh = new PDO('mysql:host=' . $host2 . ';dbname=' . $db_name2, $user2, $password2);
  $sth = $dbh-&gt;prepare($query2);
  
  //do something else
  </code></pre>
  
  <p>Sorry for the edit but here's another consideration. With each of these I obviously should check whether or not the connection was successful and throw an exception if it wasn't:</p>
  
  <pre><code>if (!$dbh) {
      $err=$dbh-&gt;errorInfo();
      throw new Exception('Could not connect: ' . $err[2]);
  }
  </code></pre>
  
  <p>I don't suppose there's a way to avoid this, unless I create all the connections at the same time and do <code>if (!dbh1|!dbh2) { ... }</code>. Just something else to consider.</p>