Posted by Marcus on 11/24/19 11:28
Alucard wrote:
> Hi all.
>
> I am a newbie in PHP. Recently I found that there are mainly two ways
> to fetch mysql(or other DB) data: by object or by array.
>
> What is the main differences between them? Will the server use more
> resources (just my thought) when fetching by object? Or any other
> reasons?
>
> Thanks in advance for advises.
>
In my experience there is no difference between the two. I would guess
that if you got down to specifics fetching by array *might* be a bit
faster, but I think it would be so small it wouldn't affect your script
at all.
The difference is after you run your query with either:
$row = mysql_fetch_object($result) or
$row = mysql_fetch_array($result)
you would reference your fields by
$row->field or
$row[index]
respectively. I like using mysql_fetch_object because it seems natural
to me to reference with ->field, but it's up to you.
Navigation:
[Reply to this message]
|