PHP functions for MySql : mysqli_fetch_array()

The mysqli_fetch_array() function fetches a result row as an associative array. It returns an array of strings that corresponds to the fetched row. The syntax is :
mysqli_fetch_array( result, resulttype )
Where :
  • result specifies a result set identifier returned by mysqli_query().
  • resulttype is optional, it specifies what type of array that should be produced. The possble values of resulttype are : MYSQLI_ASSOC, MYSQLI_NUM, MYSQLI_BOTH. The MYSQLI_ASSOC is default one.
Example :
<?php

  $server = "localhost";
  $username = "root";
  $password = "";
  $dbName = "mydb";

  $connection = mysqli_connect($server, $username, $password, $dbName);

  $sql = "SELECT * from employee";
  $result = mysqli_query($connection, $sql);
  $row = mysqli_fetch_array($result);

  echo $row[0] . " " . $row[1] . " " . $row[2] . " " . $row[3];

  mysqli_close($connection);

?>
Output :

101 John 2000 Boston


Next Topic :