Fetch all rows and return the result-set as an associative array in PHP
Description
The following code shows how to fetch all rows and return the result-set as an associative array.
Example
//from w w w.j a v a 2 s . co m
<?php
$con=mysqli_connect("localhost","root","","test");
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT name,id FROM employee";
$result=mysqli_query($con,$sql);
// Fetch all
mysqli_fetch_all($result,MYSQLI_ASSOC);
// Free result set
mysqli_free_result($result);
mysqli_close($con);
?>