Hello kartik,
Actually there are many functions that are available in PHP to retrieve the data from the MySQL database.
The Function are :mysqli_fetch_array(), mysqli_fetch_row(), mysqli_fetch_assoc(), mysqli_fetch_object().
Few functions are mentioned below:
mysqli_fetch_array() – It is used to fetch the records as a numeric array or an associative array.
Sample code:
// Associative or Numeric array
$result=mysqli_query($DBconnection,$query);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
echo "Name is $row[0]
";
echo "Email is $row['email']
"; |
mysqli_fetch_row() – It is used to fetch the records in a numeric array.
Sample code:
//Numeric array
$result=mysqli_query($DBconnection,$query);
$row=mysqli_fetch_array($result);
printf ("%s %s\n",$row[0],$row[1]); |
mysqli_fetch_assoc() – It is used to fetch the records in an associative array.
Sample code:
// Associative array
$result=mysqli_query($DBconnection,$query);
$row=mysqli_fetch_array($result);
printf ("%s %s\n",$row["name"],$row["email"]); |
mysqli_fetch_object() – It is used to fetch the records as an object.
Sample code:
// Object
$result=mysqli_query($DBconnection,$query);
$row=mysqli_fetch_array($result);
printf ("%s %s\n",$row->name,$row->email);
There are many other function that can be used to retrieve data from database for different purpose according to the user use of data.
Thank you! |