title: How can i store PDO objects
body: <p>Right now every time i need to run a query i call a function named <code>connection()</code> that creates a new PDO object.</p>
  
  <pre><code>function connection(){
      $host   = 'localhost';
      $user   = 'user';
      $pass   = 'password';
      $dbName = 'db_name';
      new PDO("mysql:host=$host; dbname=$dbName", $user, $pass);
  }
  
  $db = connection();
  $query = 'SELECT ...';
  $stmt  = $db-&gt;prepare($query);
  $stmt-&gt;execute();
  </code></pre>
  
  <p>The problem is the web site takes exactly 1 second to create this object and, as you can image, if i need to run 4 queries the page will load in 4 seconds. So, is there any way i can store this PDO object to optimize performance?</p>
  
  <p>I'm using this function in multiple files so i need it.</p>