Different between mysql_fetch_object and mysql_fetch_assoc/array?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alucard

    Different between mysql_fetch_object and mysql_fetch_assoc/array?

    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.

  • Marcus

    #2
    Re: Different between mysql_fetch_obj ect and mysql_fetch_ass oc/array?

    Alucard wrote:[color=blue]
    > 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.
    >[/color]

    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_obj ect($result) or
    $row = mysql_fetch_arr ay($result)

    you would reference your fields by

    $row->field or
    $row[index]

    respectively. I like using mysql_fetch_obj ect because it seems natural
    to me to reference with ->field, but it's up to you.

    Comment

    • Alucard

      #3
      Re: Different between mysql_fetch_obj ect and mysql_fetch_ass oc/array?

      Ha!

      Same to you. I like to use (DB)_fetch_obje ct with same reason!

      Anyway, thanks for your advise.

      Comment

      Working...