|
Posted by Jerry Stuckle on 11/26/07 13:15
Erwin Moller wrote:
> 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.
>
Erwin,
The overhead in creating an associative array is negligible.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|