How to fetch data from mysql using PHP

2

- Advertisement -

In the previous tutorial, I explained how to insert data into MySQL using PHP. Now in this tutorial, I will explain how to fetch data from MySQL using PHP.
We can fetch the data from MySQL using the following methods given below :

  • mysqli_fetch_array
  • mysqli_fetch_row
  • mysqli_fetch_assoc
  • mysqli_fetch_object

First Create a database with name demo. Now create a table with name data.
Here the strcuture of table

structure of data table

Code for mysql connection with php(config.php)

Fetch data from mysql using mysqli_fetch_array

Fetch a result row as an associative array, a numeric array and also it fetches by both associative & numeric array.This function will actually return an array with both the contents of mysqli_fetch_row and mysqli_fetch_assoc merged into one. It will both have numeric and string keys.

Fetch data from mysql using mysqli_fetch_row

Mysqli_fetch_row fetch result row an numeric way. This function return a row where the value will come in the order as they are defined in the query, and the keys will span from 0 to one less than the number of columns selected.

Fetch data from mysql using mysqli_fetch_assoc()

Fetch a result row as an associative array.This function will return a row as an associative array where the column names will be the keys storing corresponding value.

Fetch data from mysql using mysqli_fetch_object()

Fetch a result row as an object.

Download Source Code (How to fetch data from mysql using PHP)
Size: 27.6 KB
Version: V 2.0

- Advertisement -

Leave A Reply

Your email address will not be published.