title: MySQLi Error Handling?
body: <p>I started using OO-MySQLi after procedural MySQL and I have a problem.</p>
  
  <p>In production environment my system displays all errors as a custom page.
  MySQLi errors is an "error" too and I want catch them, but in documentation described only one way to do this:</p>
  
  <pre><code>if (!$mysqli-&gt;query("SET a=1")) {
      exit('An error occurred: ' . $mysqli-&gt;error);
  }
  </code></pre>
  
  <p>(just for example).
  This is a very bad way, because in my system I'm doing many things when error occurred, like logging, calling events, etc.</p>
  
  <p>Of course, I can extend mysqli class, for example:</p>
  
  <pre><code>class myMysqli {
      public function __construct(/* ... */)
      {
          parent::__construct(/* ... */);
      }
  
      public function query(/* .. */)
      {
          parent::query(/* ... */);
  
          if($this-&gt;errno !== 0)
          {
              // An error occurred
          }
      }
  }
  $mysqli = new myMysqli(/* ... */);
  $mysqli-&gt;query(/* ... */);
  </code></pre>
  
  <p>But this way I need to extend almost <strong>ALL</strong> methods where error can occur.
  Moreover, MySQLi provides prepared statements (mysqli_stmt class) that has its own errors!</p>
  
  <p>Can you know a better way to handle MySQLi errors?
  Thank you in advance.</p>
  
  <hr>
  
  <p><strong>Added</strong></p>
  
  <p>About exceptions:
  Do I understand correctly that with exceptions I need do something like this:</p>
  
  <pre><code>try {
      $mysqli-&gt;query(/* ... */);
  } catch (Exception $e) {
      // An error occurred
  }
  </code></pre>
  
  <p>But this is similar to</p>
  
  <pre><code>if(!$mysqli-&gt;query(/* ... */))
  {
      // An error occured
  } 
  </code></pre>
  
  <p>What a difference?</p>