mysqli_multi_query.php : mysqli « MySQL Database « PHP






mysqli_multi_query.php

 
<?php

   $mysqli = new mysqli("127.0.0.1", "root","", "mydatabase");

   $userid = $_SESSION['userid'];

   $query = "SELECT lastname, firstname FROM user WHERE userID='$userid';";
   $query .= "SELECT product_count, CONCAT('$',total_cost) FROM sales WHERE userID='$userid'";

   if($mysqli->multi_query($query)) {
      do {
         $result = $mysqli->store_result();
         while ($row = $result->fetch_row())
            echo "$row[0], $row[1] <br />";
         if ($mysqli->more_results())
            echo "<br />";
      } while ($mysqli->next_result());
   }
?>
  
  








Related examples in the same category

1.Multiple Queries Using MySQLi
2.Parameter Binding in MySQLi
3.Use mysqli to fetch data from mysql
4.Using the mysqli Object-Oriented API
5.Using the Object-Oriented Syntax in MySQLi
6.mysqli_fetch_object.php
7.mysqli_fetch_result-2.php
8.mysqli_fetch_result.php
9.mysqli_fetch_row.php
10.mysqli_free_result.php
11.mysqli_stmt_prepare.php
12.mysqli_store_result.php
13.retrieving_multiple_rows.php