Easy Tutorial
❮ Php Xml Dom Func Filesystem Rewind ❯

PHP mysqli_fetch_all() Function

PHP MySQLi Reference Manual

Example

Fetch all rows from the result set as an associative array:

<?php
// Assume database user: root, password: 123456, database: tutorialpro
$con = mysqli_connect("localhost", "root", "123456", "tutorialpro");
if (mysqli_connect_errno($con)) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql = "SELECT name, url FROM websites ORDER BY alexa";
$result = mysqli_query($con, $sql);

// Fetch data
mysqli_fetch_all($result, MYSQLI_ASSOC);

// Free result set
mysqli_free_result($result);

mysqli_close($con);
?>

Definition and Usage

The mysqli_fetch_all() function fetches all rows from the result set as an associative array, a numeric array, or both.

Note: This function is available only with the MySQL Native Driver.


Syntax

Parameter Description
result Required. Specifies a result set identifier returned by mysqli_query(), mysqli_store_result(), or mysqli_use_result().
resulttype Optional. Specifies what type of array should be produced. Can be one of the following values: MYSQLI_ASSOC, MYSQLI_NUM, MYSQLI_BOTH

Technical Details

Return Value: Returns an associative or numeric array containing the result rows.
PHP Version: 5.3+
--- ---
❮ Php Xml Dom Func Filesystem Rewind ❯