PHP

How to fetch data from mysql using PHP

Fetch data from MySQL using PHP
Written by Anuj kumar

In 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 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

About the author

Anuj kumar

I'm Anuj kumar a web developer with 4+ year experience .I write blogs in my free time. I love to learn new technologies and share with others. I founded PHPGurukul in September 2015. The main aim of this website to is provide php , jquery , mysql , phpoops and other web development tutorials. I am trying best effort to make PHPGurukul useful for every single moment spend on this website. If you think this website is useful to visit please share with your friend and buddies.