Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql result fetching comparison using php

Tags:

php

mysql

Which one is better to fetch data from mysql database using PHP and why?

mysql_fetch_row() 
mysql_fetch_assoc() 
mysql_fetch_array()
like image 308
Sadat Avatar asked Mar 01 '23 07:03

Sadat


1 Answers

mysql_fetch_row() It returns array with numeric index/key. Usually it is the faster compare with two other methods.

mysql_fetch_assoc() It returns array with column name as key. It is slightly slower than mysql_fetch_row().

mysql_fetch_array() It returns returns essentially two arrays. One with an associative based key index and one with a numeric index. mysql_fetch_array() without specifying which method you want (either MYSQL_NUM or MYSQL_ASSOC) always returns a double array. And it is considerably more inefficient as compared to mysql_fetch_row() or mysql_fetch_assoc(). You can set the result type as second parameter.

I think, actually those method has no significant difference.

like image 191
Sadi Avatar answered Mar 06 '23 16:03

Sadi