Am I using mysql_fetch_assoc and mysql_fetch_array the corre

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jazz090
Forum Contributor
Posts: 176
Joined: Sun Apr 12, 2009 3:29 pm
Location: England

Am I using mysql_fetch_assoc and mysql_fetch_array the corre

Post by jazz090 »

When I usually call something from a database, I am either dealing with one record exclusivity or a whole bunch of record. I always use mysql_fetch_assoc when dealing with single record returns e.g. username-password authentication but if i want to display who is online for example, I just run a while ($user = mysql_fetch_array($rb_response)). Is this the correct approach?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Am I using mysql_fetch_assoc and mysql_fetch_array the c

Post by AbraCadaver »

It doesn't matter, it depends on how you want to fetch the array. fetch_assoc fetches only an associative array and fetch_array can fetch either a numerical or associative or by default both. I tend to always use mysql_fetch_assoc() or the mysqli functions.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply