Search blog

Friday, April 6, 2018

Why You Shouldn't Be Using mysqli_fetch_array()?

While researching as to why not to use mysqli_fetch_array(), and instead use mysqli_fetch_row() or mysqli_fetch_assoc(), I ran into this old post, which well explains the reason. The test results for each of these functions may not be as per contemporary test case, but it will still give you a good idea as to why mysqli_fetch_array() shouldn't be used

Benchmark on a table with 38567 rows:

mysql_fetch_array
MYSQL_BOTH: 6.01940000057 secs
MYSQL_NUM: 3.22173595428 secs
MYSQL_ASSOC: 3.92950594425 secs

mysql_fetch_row: 2.35096800327 secs
mysql_fetch_assoc: 2.92349803448 secs

As you can see, it's twice as efficient to fetch either an array or a hash, rather than getting both.  It's even faster to use fetch_row rather than passing fetch_array MYSQL_NUM, or fetch_assoc rather than fetch_array MYSQL_ASSOC.

Don't fetch BOTH unless you really need them, and most of the time you don't.

SOURCE: http://bit.ly/2qaSyFr

No comments:

Post a Comment

Thank you for your Feedback!
www.evagabond.me

Top 5 Posts (Weekly)