Mostly used php functions for fetching data from database are given. I have listed 5 php functions to fetching data.
- mysql_fetch_assoc()
- mysql_fetch_object()
- mysql_fetch_array()
- mysql_fetch_row()
- mysql_result()
1] mysql_fetch_assoc() mysql_fetch_assoc() fetch the data from database through associative array. [code type=php] <html> <?php $query=mysql_query(“select * from tb”); $query1=mysql_fetch_assoc($query); echo $query1[‘name’]; ?> </html> [/code] 2] mysql_fetch_row() mysql_fetch_row() function will fetches the data from database through numeric array. [code type=php] <html> <?php $query=mysql_query(“select * from tb”); $query1=mysql_fetch_row($query); echo $query1[0]; ?> </html> [/code] 3] mysql_fetch_array() mysql_fetch_array() function fetches data from database through both numeric array and associative array. [code type=php] <html> <?php $query=mysql_query(“select * from tb”); /*Associative array to get data */ $query1=mysql_fetch_array($query); echo $query1[‘name’]; /* Numeric array to get data */ echo $query1[0]; ?> </html> [/code] 4] mysql_fetch_object() mysql_fetch_object() function fetches the data from database through object. [code type=php] <html> <?php $query=mysql_query(“select * from tb”); $query1=mysql_fetch_object($query); echo $query1->name; ?> </html> [/code] 5] mysql_result() [code type=php] <html> <?php $query=mysql_query(“select name from tb”); $query1=mysql_result($query,0); echo $query1; ?> </html> [/code]
nice explaination