• PHP Video Tutorials

PHP - Function MySQLi Fetch Array



Syntax

mysqli_fetch_array(result,resulttype);

Definition and Usage

It is used to fetchs a result row as an associative array

Return Values

It returns an array of strings that corresponds to the fetched row.

Parameters

Sr.No Parameters & Description
1

result

It specifies the result set identifier

2

resulttype

It specifies what type of array that should be produced

Example

Try out the following example

<?php
   $connection_mysql = mysqli_connect("localhost","username","password","db");
   
   if (mysqli_connect_errno($connection_mysql)){
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }
   
   $sql = "SELECT name,age FROM emp";
   $result = mysqli_query($connection_mysql,$sql);
   $row = mysqli_fetch_array($result,MYSQLI_NUM);
   
   print $row[0];
   print "\n";
   print $row[1];
   
   $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
   print $row["name"];
   print "\n";
   print $row["age"];
   
   mysqli_free_result($result);
   mysqli_close($connection_mysql);
?>
php_function_reference.htm
Advertisements