PHP mysqli_fetch_all() function is used to fetch all result rows as an associative array, a numeric array, or both.
Syntax
array mysqli_fetch_all(result, resulttype);
Parameter | Description |
---|---|
result : | Required parameter. Mention a result set identifier returned by mysqli_query(). |
resulttype : | Optional paramater. Mention type of array that should be generated. The resulttype could be MYSQLI_ASSOC or MYSQLI_NUM or MYSQLI_BOTH. |
Return Values : | Returns associative array or numeric array that hold the result rows. |
<?php $con = mysqli_fetch_allt("localhost","user","password","db"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql = "SELECT fname, lname FROM employee"; $sql_result = mysqli_query($con, $sql); // Fetch all $array = mysqli_fetch_all($sql_result,MYSQLI_NUM); // Free result set mysqli_free_result($sql_result); mysqli_close($con); ?>