phpmysqlmysqli-multi-querymulti-query

multi_query does not run within a loop


A multi-query that I've put into another query does not run. The stored procedures in the inner query were not executed. The multi query alone is running well, but inside the loop it does not. Cold you please check, why InnerQuery does not perform inside the loop?

 <?php
 include ("../mysqli.php");
 if (mysqli_connect_errno()) {
     printf("Connection error: %s\n", mysqli_connect_error());
     exit();
 }

 # Check Start Time 
 $time1 = microtime(true); 

 ## Start 
 if ($DBquery = $mysqli->query("SELECT `id` FROM `Universe`")) {
     while($obj = $DBquery->fetch_object()){
         $id = $obj->id;
         echo "Start with Product-ID: " . $id . "<br>";

         # Defining Inner Query
         $DBInnerQuery = "
         SET @CATEGORY  := (SELECT ....);
         SET @Date      := (SELECT ...
         CALL `PROCEDURE1`; 

         SET @COUNTRY := (SELECT ....);
         CALL `PROCEDURE2`; 
         ...
         ";

         # Inner Query does not run and I don't know why:
         if ($mysqli->multi_query($DBInnerQuery)) {
             $time2 = microtime(true) - $time1;
             echo "Scan for Product-Id " . $id . " solved in " 
             . round ($time2, 4) . " seconds<br>";
         }

     }
 }
 echo "End of Product Check." . "<br>";
 ?>

Solution

  • Meanwhile, I've solved it:

     # Defining Inner Query
              CALL `PROCEDURE1;`; 
    
     # Multi Query 
     if ($mysqli->multi_query($DBInnerQuery)) {
        echo "<hr>" . "Scan for all Items solved." . "<br>";
     }
    
     $time2 = microtime(true) - $time;
     echo "Used Time: " 
         . round ($time, 4) . " Seconds<br>";
    
     echo "End." . "<br>";