title: Trouble with mysqli_multi_query
body: <p>I'm having trouble with a mysqli_multi_query. 
  I am able to <code>INSERT INTO</code> multiple times, but as soon as I include a <code>DELETE</code>, all subsequent queries do not work. Interestingly, this query works fine when pasted into the phpMyAdmin SQL box.</p>
  
  <pre><code>SET @contact_id := 1; 
  INSERT INTO `contacts_tags` (`contact_id`, `tag_id`)
      SELECT * FROM (SELECT @contact_id, 1) AS tmp
      WHERE NOT EXISTS (
          SELECT `contact_id`, `tag_id` FROM `contacts_tags` 
          WHERE `contact_id` = @contact_id AND `tag_id` = 1
          ); 
  DELETE FROM `contacts_tags`
      WHERE `contact_id`=@contact_id AND `tag_id` NOT IN (1); 
  </code></pre>
  
  <p>All queries up to the <code>DELETE</code> query execute as expected from my php code. </p>
  
  <p>Adding a further queries as logs (see below), Step 1, @contact_id, Step 2a, Step 2b and Step 2c are all inserted. The 'Last' one does not. (And of course neither does the <code>DELETE</code> one. </p>
  
  <pre><code>INSERT INTO `tf_logs` (`query`) VALUES ('Step0');
  SET @contact_id := 1; 
  INTO `tf_logs` (`query`) VALUES ('Step1');
  INSERT INTO `contacts_tags` (`contact_id`, `tag_id`)
      SELECT * FROM (SELECT @contact_id, 1) AS tmp
      WHERE NOT EXISTS (
          SELECT `contact_id`, `tag_id` FROM `contacts_tags` 
          WHERE `contact_id` = @contact_id AND `tag_id` = 1
          ); 
  INSERT INTO `tf_logs` (`query`) VALUES (@contact_id); 
  INSERT INTO `tf_logs` (`query`) VALUES ('Step 2a'); 
  INSERT INTO `tf_logs` (`query`) VALUES ('Step 2b'); 
  INSERT INTO `tf_logs` (`query`) VALUES ('Step 2c');
  DELETE FROM `contacts_tags`
      WHERE `contact_id`=@contact_id AND `tag_id` NOT IN (1); 
  INSERT INTO `tf_logs` (`query`) VALUES ('Last'); 
  </code></pre>
  
  <p>To create this query, I incrementally append values to a string, then use <code>mysqli_multi_query</code>, as below. To check exactly what the variable contains, I have emailed myself the final query. Copying and pasting the email contents into phpMyAdmin executes the queries exactly as intended. </p>
  
  <pre><code>$queryString = "";
  $queryString .= "INSERT INTO `tf_logs` (`query`) VALUES ('Step0'); ";
  $queryString .= "
  SET @contact_id := $contactId; ";
  //...and so on
  
  if(mysqli_multi_query($connection,$queryString)) {
  echo "Success.";
  
  $to = "abc@xyz.com";
  $subject = "SQL query";
  $headers = "From: abc@xyz.com";
  mail($to,$subject,$queryString,$headers);
  } else {
      echo "Error.";
  }
  </code></pre>
  
  <p>I'm sure I'm missing something obvious here, but a few days of googling has driven me to insanity. Thanks in advance!</p>