Hello.

I'm used to using the mysql_fetch_assoc command, and always, and I don’t see any differences in speed (site usability) and convenience with the commands mysql_fetch_row , mysql_fetch_array ... can anyone tell me in amateur language, so to speak, where it’s useful to use the above commands and where is better do not use?

  • Wherever it is convenient for you to use fetch_assoc - use it, you did not notice differences in speed because there are practically none (or rather, they can be safely ignored) - Zowie
  • it is generally inappropriate to use mysql_fetch_assoc. nowhere. - FLK
  • dear gurus, glimpse at least 2 arguments for or against, and looking at the top 2 comments I don’t know who to believe - frank
  • Two arguments led) - Palmervan
  • Should be ashamed of such arguments, what do young people teach? - FLK

3 answers 3

dear gurus, glimpse at least 2 arguments for, or against, and looking at the top 2 comments I don’t know who to believe

mysql_fetch_array -> $arr[0] and $arr['id'] will return the same from the database

mysql_fetch_assoc -> $arr[0] returns Undefined offset: 0

Suppose using the list() function whose indexes are numbers, when data is requested by the function mysql_fetch_assoc it will return nothing except Undefined offset

There are many examples and subtleties of using! Led the first thing I remembered!

    mysql_ * functions are insecure and outdated, plus a bunch of other cons, so it is recommended to use the PDO library. Why use PDO

    • one
      @FLK - I answered a specific question from TS'a, but for good, yes, it's really better to use PDO. About the unsafe, so as not to be unfounded - please provide proof. Yes, and not everywhere PDO is appropriate, for example, if a procedural code is written - Zowie
    • firstly, php has no procedural code as such; for security, at least, everyone's favorite construct: mysql_query ("select * from table where id = $ id"); already unsafe. - FLK

    If you get confused, use mysql_fetch_array with the parameter MYSQL_BOTH , this is a combination of mysql_fetch_assoc and mysql_fetch_row . In 90% of cases I use mysql_fetch_assoc , simply because I like the combination of letters in this phrase))) Yes, and as it is in my opinion more pleasant to read)) We are all programmers with our oddities))))

    Here's how to use Dakidka:

     function MySQLQ_once($q) { $res = MySQLQ($q); while($row = mysql_fetch_array($res,MYSQL_NUM)) return $row[0]; return false; } function MySQLQ_array($q) { $res = MySQLQ($q); while($row = mysql_fetch_assoc($res)) return $row; return false; }