title: How do you efficiently connect to mysql in php without reconnecting on every query
body: <p>I'm pretty sick of having to rewrite my code every time I learn something new about php (like the fact that mysql connections cannot be passed around in a session as a handle).</p>
  
  <p>How do you implement mysql connection in your projects? A lot of people have proposed "connection pooling", but after reading the manual i'm still lost. It's like: "connection pooling is mysql_pconnect!" - me: "and...? how is that any different in reality? can you pass around a mysql_pconnect in a session? why is this seemingly mysterious aura??"</p>
  
  <p>Let me explain my situation. I have a function called "query1":</p>
  
  <pre><code>function query1($query)
  {
      $db = new mysql(HOST,USER,PASS,DBNAME);
      $result = $db-&gt;query($query);
      $db-&gt;close();
      return $result;
  } 
  </code></pre>
  
  <p>This is seems like a squanderous and inefficient way of querying a db (<strong>especially</strong> since you need a mysql handle for functions like mysql_real_escape_string). <em>What is the correct form to do it? Can someone please help me?</em></p>
  
  <p>Thank you I'd really appreciate a good honest answer.</p>