Friday, March 21, 2014

mysql_fetch_row() vs mysql_fetch_assoc() vs mysql_fetch_array()

What will the different functions return?

All of the mentioned functions will return an array, the differences between them is what values that are being used as keys in the returned object.
  • This function will return a row where the values will come in the order as they are defined in the SQL query, and the keys will span from 0 to one less than the number of columns selected.
  • This function will return a row as an associative array where the column names will be the keys storing corresponding value.
  • This function will actually return an array with both the contents of mysql_fetch_rowand mysql_fetch_assoc merged into one. It will both have numeric and string keys which will let you access your data in whatever way you'd find easiest.
    It is recommended to use either _assoc or _row though.

No comments:

Post a Comment

Please Comment Here!

How to backup and download Database using PHP

< ?php $mysqlUserName = 'databaseusername' ; $mysqlPassword = 'databasepassword' ; $mysqlHostNa...