title: php shared db connection ( design pattern help )
body: <p>I have a small php app that I want to build a layer of db abstraction on top of with a few "model" type classes. </p>
  
  <p>I'm using ezSQL_mysql to do the db work.</p>
  
  <p>My question is what is the best way to design the app? Should I use a singleton pattern to share the db connection? Should my "model" classes extend ezSQL_mysql ? Or maybe I'm totally off base here and need to do something else.  </p>
  
  <p>What I need is something like this </p>
  
  <p>Controller.php </p>
  
  <pre><code>   $db = new ezSQL_mysql($db_user, $db_passwd, $db_database, $db_host);
  
  
     $user = new User();
     $user-&gt;update_email($new_email);
  
     $sale = new Sale();
     $sale-&gt;purchase($amount); 
  </code></pre>
  
  <p>User_model.php </p>
  
  <pre><code>class User {
  
     /* uses $db connection */
     function update_email(){
       /* do something */
     };
  }
  </code></pre>
  
  <p>Sale_model.php </p>
  
  <pre><code>class Sale {   
     /* uses $db connection*/
  
     function purchase () {
      /* do something */ 
     }
  }
  </code></pre>