How to fetch data from mysql using PHP

1539 0

$1*/ mo hosting! Get going with GoDaddy!

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 :

  • mysql_fetch_array
  • mysql_fetch_row
  • mysql_fetch_assoc
  • mysql_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 mysql_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 mysql_fetch_row and mysql_fetch_assoc merged into one. It will both have numeric and string keys.

Fetch data from mysql using mysql_fetch_row

Mysql_fetch_row fetch result row an numeric way. This function return a row where the valuew 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 mysql_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 mysql_fetch_object()

Fetch a result row as an object.

In this article

Join the Conversation