You are here : phpmysqlimysqli_fetch_assoc

mysqli_fetch_assoc() - mysqli

The mysqli_fetch_assoc() function fetches a result row as an associative array.


Syntax

mysqli_fetch_assoc(result);


Example

<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql="SELECT Lastname,Age FROM Persons ORDER BY Lastname";
$result=mysqli_query($con,$sql);

// Associative array
$row=mysqli_fetch_assoc($result);
printf ("%s (%s)\n",$row["Lastname"],$row["Age"]);

// Free result set
mysqli_free_result($result);

mysqli_close($con);
?> 


Output / Return Value


Limitations


Alternatives / See Also


Reference