title: How do I ensure I caught all errors from MySQLi::multi_query?
body: <p>The <a href="http://us3.php.net/manual/en/mysqli.multi-query.php" rel="noreferrer">docs for <code>multi_query</code></a> say:</p>
  
  <blockquote>
    <p>Returns FALSE if the first statement failed. To retrieve subsequent errors from other statements you have to call mysqli_next_result() first.</p>
  </blockquote>
  
  <p>The <a href="http://us3.php.net/manual/en/mysqli.next-result.php" rel="noreferrer">docs for <code>next_result</code></a> say:</p>
  
  <blockquote>
    <p>Returns TRUE on success or FALSE on failure.</p>
  </blockquote>
  
  <p>Finally, the example posted in the docs for <code>multi_query</code> use the return value from <code>next_result</code> to determine when there are no more queries; e.g. to stop looping:</p>
  
  <pre><code>&lt;?php
  $mysqli = new mysqli("localhost", "my_user", "my_password", "world");
  
  /* check connection */
  if (mysqli_connect_errno()) {
      printf("Connect failed: %s\n", mysqli_connect_error());
      exit();
  }
  
  $query  = "SELECT CURRENT_USER();";
  $query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5";
  
      /* execute multi query */
      if ($mysqli-&gt;multi_query($query)) {
          do {
              /* store first result set */
              if ($result = $mysqli-&gt;store_result()) {
                  while ($row = $result-&gt;fetch_row()) {
                      printf("%s\n", $row[0]);
                  }
                  $result-&gt;free();
              }
              /* print divider */
              if ($mysqli-&gt;more_results()) {
                  printf("-----------------\n");
              }
          } while ($mysqli-&gt;next_result()); // &lt;-- HERE!
      }
  
      /* close connection */
      $mysqli-&gt;close();
      ?&gt;
  </code></pre>
  
  <p>I don't know the number of queries provided, nor do I know anything about the SQL that I'm going to execute. I therefore can't just compare the number of queries against the number of returned results. Yet I want to display an error message to the user if, say, the third  query was the broken query. But I don't seem to have a way to tell if <code>next_result</code> failed because there were no more queries to execute, or if it's because there was an error in the SQL syntax.</p>
  
  <p>How can I check all the queries for errors?</p>