note 42305 deleted from function.mysql-fetch-assoc by philip
| From: | philip@php.net | Date: | Sun, 08 Aug 2004 16:54:34 +0000 |
| Subject: | note 42305 deleted from function.mysql-fetch-assoc by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-74252@lists.php.net to get a copy of this message | ||
Note Submitter: Matt AKA Junkie
----
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().