note 42305 added to function.mysql-fetch-assoc

From: Date: Tue, 11 May 2004 18:01:41 +0000
Subject: note 42305 added to function.mysql-fetch-assoc
Groups: php.notes 
Request: Send a blank email to php-notes+get-69475@lists.php.net to get a copy of this message
Good practice (in my opinion) of using mysql_fetch_* is to use mysql_fetch_row() whenever possible. The best way to use it is when you know what exact columns you are selecting (example below). <? $fetch_row = mysql_fetch_row( mysql_query("select col1,col2,col3 from table where col4 = 1")); // [0] will be col1, [1] will be col2, and so on $fetch_assoc = mysql_fetch_assoc( mysql_query("select * from table2 where colid = 50")); // ['col1a'] would be col1a, this is best for possible changing database structure ?> Of course, if you're writing open-source software and the user might be editting queries, either make sure to note that they don't change the order of tables in a _row() query or use _assoc() whenever possible (at the cost of a micro-miniscule amount of memory and speed). Another note: if the results you are getting is very large or you are selecting more than 10 columns, it might be more convenient to use _assoc(). ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-assoc.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42305 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42305&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42305&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69475) next »