title: Wait for mysqli::multi_query to finish before executing next statement
body: <p>I have some code that uses <code>Mysqli::multi_query</code> to drop and rebuild a development database from a flat <code>.sql</code> file. After rebuilding the mysqli connection is closed and the code then reconnects to that DB with <code>PDO</code> to run queries against it.</p>
  
  <pre class="lang-php prettyprint-override"><code>/* Drop and Rebuild DB using mysqli::multi_query */
  $mysqli = new mysqli($host, $user, $pass, $db);
  if ($mysqli-&gt;connect_errno) {
      die('Failed to connect to MySQL: (' . $mysqli-&gt;connect_errno . ') ' . $mysqli-&gt;connect_error);
  }
  
  $query = file_get_contents("DROPandREBUILD.sql");
  
  if (!$mysqli-&gt;multi_query($query))
      die("Failed to refresh db: $this-&gt;target_db");
  
  $mysqli-&gt;close();
  
  /* Execute queries against rebuilt database using PDO */
  try {
      $sth = new PDO("mysql:host=$host;dbname=$db", $user, $ass);
      $test1 = $sth-&gt;query("SELECT * FROM tbl");
      var_dump($sth-&gt;errorInfo());
      $test2 = $sth-&gt;query("SHOW COLUMNS FROM tbl");
      var_dump($sth-&gt;errorInfo());
  }
  catch(PDOException $e) {
      die($e-&gt;getMessage());
  }
  </code></pre>
  
  <p>Output from 1st <code>var_dump</code> (<code>$test1</code>):</p>
  
  <pre><code>array(3) {
    [0]=&gt;string(5) "00000"
    [1]=&gt;NULL
    [2]=&gt;NULL
  }
  object(PDOStatement)#3 (1) {
    ["queryString"]=&gt;string(31) "SELECT * FROM tbl"
  }
  </code></pre>
  
  <p>Output from 2nd var_dump (<code>$test2</code>):</p>
  
  <pre><code>array(3) {
     [0]=&gt;string(5) "42S02"
     [1]=&gt;int(1146)
     [2]=&gt;string(45) "Table 'db.tbl' doesn't exist"
  }
  bool(false)
  </code></pre>
  
  <p>Why does the query from <code>$test2</code> fail? If I remove the <code>mysqli</code> code bock then everything works perfectly. Both queries are running against the same <code>tbl</code> in the same <code>db</code>. Is there something going on that is asynchronous and if so how do I force my script to wait for the <code>mysqli::multi_query</code> to finish executing before instantiating <code>PDO</code>? </p>