title: I get Exception unknown error, after querying DataBase for the second time in PHP MYSQLI
body: <p>I'm using this code:</p>
  
  <pre><code>class db extends mysqli
  {
      protected static $instance;
      protected static $options = array();
  
      private function __construct() {
          $o = self::$options;
  
          // turn of error reporting
          mysqli_report(MYSQLI_REPORT_OFF);
  
          // connect to database
          @parent::__construct(isset($o['host'])   ? $o['host']   : 'localhost',
                               isset($o['user'])   ? $o['user']   : 'root',
                               isset($o['pass'])   ? $o['pass']   : '',
                               isset($o['dbname']) ? $o['dbname'] : 'world',
                               isset($o['port'])   ? $o['port']   : 3306,
                               isset($o['sock'])   ? $o['sock']   : false );
  
          // check if a connection established
          if( mysqli_connect_errno() ) {
              throw new exception(mysqli_connect_error(), mysqli_connect_errno()); 
          }
      }
  
      public static function getInstance() {
          if( !self::$instance ) {
              self::$instance = new self(); 
          }
          return self::$instance;
      }
  
      public static function setOptions( array $opt ) {
          self::$options = array_merge(self::$options, $opt);
      }
  
      public function query($query) {
          if( !$this-&gt;real_query($query) ) {
              throw new exception( $this-&gt;error, $this-&gt;errno );
          }
  
          $result = new mysqli_result($this);
          return $result;
      }
  
      public function prepare($query) {
          $stmt = new mysqli_stmt($this, $query);
          return $stmt;
      }    
  }
  </code></pre>
  
  <p>I have some functions that update, insert, display DB content.</p>
  
  <p>Now if I execute this code directly, no problem:</p>
  
  <pre><code>$sql = db::getInstance();
  $sql-&gt;set_charset("utf8");
  $sql-&gt;query("UPDATE ads SET text='moooo' WHERE id=1") ;
  </code></pre>
  
  <p>But if I use two functions one to display some content and the second to update, I get an unknown exception error and DB won't be updated!</p>
  
  <p>Here is an example where I get error:</p>
  
  <pre><code>$sql = db::getInstance();   
  $sql-&gt;set_charset("utf8"); 
  if(ad_exists($mq-&gt;id)){
  $sql-&gt;query("UPDATE ads SET text='moooo' WHERE id=1") ;
  }
  </code></pre>
  
  <p>And here is how the ad_exist function looks like:</p>
  
  <pre><code>function ad_exists($id){
      $sql = db::getInstance();   
      $sql-&gt;set_charset("utf8");  
      $result = $sql1-&gt;query("SELECT * FROM ads WHERE id=".$id);
      $sql-&gt;close();
      if($result-&gt;num_rows&gt;0) {$result-&gt;close();
      return true;}
      else {$result-&gt;close();
          return false;}
  }
  </code></pre>
  
  <p>I've been going about closing connections after queries, preparing statements instead of direct queries, trying to make db object global or passing it as a variable, nothing seems to work, can't get over this error.</p>