Reply to Re: Speciality in mysql_fetch_array

Your name:

Reply:


Posted by Erwin Moller on 11/26/07 10:22

pradeep wrote:
> Dear all,
>
> I want to know the difference between mysql_fetch_array() and
> mysql_fetch_row().
>
> I know that mysql_fetch_row() return data in numeric array while
> mysql_fetch_array() return data in numeric as well as in associative
> array.
>
> But my question is, why it returns in both format. Is it wastage of
> memory ?
> Why this wastage is necesarry ?

Hi,

The answer is simple, if you want an assoc array, you can use
mysql_fetch_array().

I always prefer constructs like this in my code:
echo $row["firstname"];

above

echo $row[3];

Since the former leaves you without doubt which column you are using.
And also: If you expand your query to get more columns, an index of an
array might easily get you confused.

But if you like the array-indexes more, just use them.
I expect there must be less overhead involved when no assoc arrays are
created and returned.

So as far as I can tell: it is not a waste of memory, but it offers you
the choice what you want:
1) faster code/less IO (use only indexes)
2) better readable/more robust code. (use assoc arrays)

just my 2 cent.

Regards,
Erwin Moller

>
> Thanks in advance.
>
> BYe.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация