Different type of Fetching Function in Mysql

Abhigyan Singh 22nd Jan 2013

All the fetching function is used to fetch data from mysql database. But its data representation and use can be different. No need to confuse while using this function. Programmer can used any of the fetching function below.

For best understanding, refer this table

Different type of fetching function is given below:
1.    MYSQL_FETCH_ROW()
2.    MYSQL_FETCH_ARRAY()
3.    MYSQL_FETCH_ASSOC()
4.    MYSQL_FETCH_OBJECT()

1.    MYSQL_FETCH_ROW():  It is used to fetch data in numeric array. It gives result row as a numeric array.

$result=mysql_query("select * from user_table");
$result_row=mysql_fetch_row($result);
echo $result_row[0];
echo $result_row[1];
echo $result_row[2];
?>

Result:   1    Discuss   Desk

2.    MYSQL_FETCH_ARRAY(): It is used to fetch data in numeric array as well as associative array . It gives result row as a numeric array as well as associative array.

$result=mysql_query("select * from user_table");
$result_row=mysql_fetch_row($result);
echo $result_row[0];
echo $result_row[1];
echo $result_row[2];

/* numeric array as well as associative array */

echo $result_row[id];
echo $result_row[first_name];
echo $result_row[last_name];
?>

Both Result:   1    Discuss   Desk

3.    MYSQL_FETCH_ASSOC(): It is used to fetch data in associative array. It gives result row as a associative array.

$result=mysql_query("select * from user_table");
$result_row=mysql_fetch_row($result);
echo $result_row[id];
echo $result_row[first_name];
echo $result_row[last_name];
?>

Result:   1    Discuss   Desk

4.    MYSQL_FETCH_OBJECT(): It is used to fetch data as object. It gives result row as a object.

$result=mysql_query("select * from user_table");
$result_row=mysql_fetch_row($result);
echo $result_row->id;
echo $result_row->first_name;
echo $result_row->last_name;
?>

Result:   1    Discuss   Desk
 

Authored By Abhigyan Singh

He is a continuous blogger and has blogged on different topic. He loves to surf Internet and always trying to get new Idea about new Technology and Innovations and sharing these great information to all the technology lovers.

ALSO ON DISCUSS DESK