title: Singleton database class method
body: <p>I'm trying to write a query() method for a singleton database class. I have this but it ain't flying just yet and was looking for some inspiration.</p>
  
  <pre><code>&lt;?php
  class Database
  {
   static private $instance = null;
   protected $mysqli;
  
   static public function getInstance()
   {
       if (null === self::$instance) {
           self::$instance = new self;
       }
       return self::$instance;
   }
  
   private function __construct(){
          if(!$this-&gt;mysqli = new mysqli('localhost','user','pass','db'))
              throw new Exception('Error - Database connection');
   }
  
   public function query($query) {
      while ($this-&gt;mysqli-&gt;query($query))
      {
          $row = $this-&gt;mysqli-&gt;fetch_assoc();
      }
      return $row; // loop through array
   }
  
   private function __clone(){}
  
  }
  ?&gt;
  </code></pre>
  
  <p>I'm not entirely sure if I'm going down the correct road. Will mysqli work in this context?
  For instance the Mysqli class already has a query() method as part of its class. I'm introducing namespace clashes here?</p>
  
  <p>My query method would handle any sort of SQL statement ie. </p>
  
  <p>Example client code:</p>
  
  <pre><code>$DB = Database::getInstance();
  $DB-&gt;query("SELECT * FROM t");
  $DB-&gt;query("DELETE FROM t WHERE id=2");
  $DB-&gt;query("UPDATE u SET col = 'random' WHERE id=4");
  </code></pre>