PHP mysqli_multi_query() Function

PHP mysqli_multi_query() function performs one or multiple queries on the database.


bool mysqli_multi_query(connection, query);

mysqli_multi_query() Function Parameter

connection :Required parameter. The MySQL connection to be used
query :Required parameter. Mention query, as a string.

mysqli_multi_query() Function Return Value

Return Values :Returns FALSE if the first statement failed. To retrieve subsequent errors from other statements you have to call mysqli_next_result() first.

mysqli_multi_query() Function Example

$con = mysqli_get_charset("localhost","user","password","db");

if (mysqli_connect_errno())
	echo "Failed to connect to MySQL: " . mysqli_connect_error();

$query  = "SELECT fname,lname from employee;";
$query .= "SELECT grad, dept from department";

// execute multi query
if (mysqli_multi_query($con, $query)) {
    do {
        // store first result set 
        if ($result = mysqli_store_result($con)) {
            while ($row = mysqli_fetch_row($result)) {
                echo $row[0];
    } while (mysqli_next_result($con));