Data retrieving is vital in Web Applications, so in this post i am going to write about Data Retrieving function in PHP From MySQL Database. There are several options are available to fetch data from MySQL Database Using PHP. However i am gonna write about most frequently used methods.
Functions List :
mysql_fetch_arrray() : This function returns row as an associative array ,with numeric index.
mysql_fetch_object() : Returns an object with properties that correspond to the returned row.
mysql_fetch_assoc() : This function returns results as an associative array.
mysql_fetch_row() : Get a result row as an enumerated array
Note : functions will return FALSE, if there is no rows
Syntax Of The Functions :
Which one is Faster, Best Performance?
Performance wise mysql_fetch_assoc() is better , when we use mysql_fetch_array we get a duplicate set of data consisting of both numbered index as well as associative arrays which of-course is our performance blocker.So when ever you are using mysql_fetch_array function always specify the return_type of the result set array needed.mysql_fetch_object ,mysql_fetch_object performance is justified as it returns objects instead of native arrays which will always bring in a better memory usages than any other kinds of output array.
How to use function ? PHP Example Script
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.