Multiple Queries Using MySQLi : mysqli « MySQL Database « PHP






Multiple Queries Using MySQLi

 
<?php

    $mysqli = new mysqli("localhost", "username", "password","mydatabase", 3306);

    $queries = "SELECT * FROM mytable; SELECT * FROM anothertable";

    if(mysqli_multi_query($mysqli, $queries)) {
        do {
            if($result = mysqli_store_result($mysqli)) {
                while($row = mysqli_fetch_row($result)) {
                    foreach($row as $key => $value) {
                        echo "$key => $value<BR/>\n";        
                    }
                }
                mysqli_free_result($result);        
            }
            if(mysqli_more_results($mysqli)) {                
                echo "<BR/>\nNext result set<BR/>\n";
            }
        } while(mysqli_next_result($mysqli));
    }
    mysqli_close($mysqli);

?>
  
  








Related examples in the same category

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