PHP - Function MySQLi Fetch Assoc


Advertisements


Syntax

mysqli_fetch_assoc(result);

Definition and Usage

It is used to fetches a result row as an associative array.

Return Values

It returns an associative array of strings representing the fetched row.

Parameters

Sr.No Parameters & Description
1

result

It specifies the result set identifier returned by mysqli_query(), mysqli_store_result() or mysqli_use_result()

Example

Try out the following example

<?php
   $connection_mysql = mysqli_connect("localhost","user","password","db");
   
   if (mysqli_connect_errno($connection_mysql)){
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }
   
   $sql = "SELECT name,salary FROM emp";
   $result = mysqli_query($connection_mysql,$sql);
   $row = mysqli_fetch_assoc($result);
   
   print $row["name"];
   print "\n";
   print $row["salary"];
   
   mysqli_free_result($result); 
   mysqli_close($connection_mysql);
?>

php_function_reference.htm

Advertisements