Different type of Fetching Function in Mysql

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
 

Share this Article on Social Media

All of my Scripts are ready to customized as per your requirement. Feel free to contact for script customization.

Contact me at discussdesk@gmail.com

"Note : It will be charged as per your customization requirement :)"

Get Updates, Scripts & Other Tutorials to Directly to your Email

Over 20000+ Happy Readers already subscribed. (We don't send spam email). Every email subscriber can get our latest updates and download our 100+ scripts.

Comments