mysql_fetch_row() VS mysql_fetch_object() VS mysql_fetch_assoc() VS mysql_fetch_array()

By | June 3, 2020

Hello Coders, here are not a very new topic for the experienced people but a very interesting topic for beginners who are always confused with these function as I mention on heading.

Today I elaborate all these with some small examples, I think you all understand very well after reading that one time. So let’s start.

Here is a table for better understanding, Suppose this is MySQL table and there is one row.

mytable.sql

id username password
1 phpcodertech 123456

 

mysql_fetch_row()

This function as the name suggests giving rows of the data which we set in the query. But one thing the values will come in order as we define on the query and indexed start with 0 and end with less than a number of selected column. 

Here is the example which shows you how this is implemented on the code.

mysql_fetch_aasoc()

This is the second PHP function which is also used for data fetching but with different format. This is also called ASSOCIATIVE array format. Means on this array, all elements have their name with values. We fetch all value using their field name.

Like the following example,

mysql_fetch_object()

All the above functions are using for fetch data from the database but with a different type. This function also does the same but fetch data from database using Object type. Please the example below for better understand.

 mysql_fetch_array()

This function, fetch result from a database as an associative array, index numeric array and both numeric and associative at the same code.

See here on the example,

Above all are the difference between these function, check if you have some improvements than please comment below.

Happy Coding…!

Subscribe For Latest Updates

Sign up to best of PHP Code Solutions, informed analysis and opinions on what matters to you.
Invalid email address
We promise not to spam you. You can unsubscribe at any time.

Leave a Reply

Your email address will not be published. Required fields are marked *