title: PHP - Improving my database model?
body: <p>I am administering a system which is fairly old. It is a code soup at the moment and bit by bit I have been refactoring the code.</p>
  
  <p>Something I noticed while doing this was that 90% of the queries were CRUD. No joins, nothing else. All really simple stuff.</p>
  
  <p>As a result I created a model class which cover's these types of query's. I then extend the model class for each table. </p>
  
  <pre><code>class Model extends MySQLi {
      public function __construct() {
          global $site;
          $mysql = $site['mysql'];
          parent::__construct($mysql['host'], $mysql['user'], $mysql['pass'], $mysql['db']);
      }
  </code></pre>
  
  <p>I don't like the use of the global but it does allow me to do this without having to worry about connection details.</p>
  
  <pre><code>&lt;?php
  class Contact extends Model {
  
      public $table = 'contact';
  
  }
  
  $Contact = new Contact;
  $Contact-&gt;get(array('where'=&gt;array('id &gt;' =&gt; 4), 'limit' =&gt; array(0, 20));
  </code></pre>
  
  <p>My concern is that if a script requires 3 tables. I will be using 3 models and thus surely that means I will have 3 independent database connections? One for each class?</p>
  
  <p>Is this going to be a problem like I think it will be?</p>
  
  <p>Is there a work around which will allow me to continue to extend MySQLi and maybe pass it an active connection instead of connection details for it to make its own connection?</p>