MySQLi - Multi Query



Syntax

bool mysqli_multi_query ( mysqli $link , string $query )

Definition and Usage

It performs a query on the database.

Example

Try out following example −

<?php
   $servername = "localhost:3306";
   $username = "root";
   $password = "";
   $dbname = "TUTORIALS";
   $conn = new mysqli($servername, $username, $password, $dbname);

   if ($conn->connect_error) {
      die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
      exit();
   } 
   if (!mysqli_query($conn, "SET a = 1")) {
      printf("Errorcode: %d\n", mysqli_error($conn));
   }
   echo 'Success... ' . mysqli_get_host_info($conn) . "\n";
   $sql = "SELECT * FROM tutorials_auto";
   
   if ($conn->multi_query($sql)) {
      do {
         /* store first result set */
         if ($result = $conn->store_result()) {
            while ($row = $result->fetch_row()) {
               printf("%s\n", $row[1]);
            }
            $result->free();
         }
         if ($conn->more_results()) {
         }
      } while ($conn->next_result());
   }
   $conn->close();
?>

The sample output of the above code should be like this −

Errorcode: 0 Success... localhost:3306 via TCP/IP sai ram sai
mysqli_useful_functions.htm
Advertisements