#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Indonesia
    Posts
    87
    Rep Power
    15
    I'm just wondering what the differences between the two of them :
    MySQL_fetch_object and MySQL_fetch_array

    I read on the PHP.net Manual, it said that when u use fetch_object the return would be object but u can only call it with their field name, but if u use array u can call it by its field name or its number

    So what the advantages of using MySQL_fetch_object rather than using MySQL_fetch_array ???

    Thx before !!!

    ------------------
    ** It's the world of Oscario **
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Some people prefer object notation?

    Actually, it's good if you already have an object created with the field names declared as properties. Then your properties will automatically be populated with the data when you call mysql_fetch_object().

    Other than that, it has no useful advantage over fetch_array().
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    56
    Rep Power
    15
    What about mysql_fetch_row? Doesn't it return an array of data from the fields too?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Indonesia
    Posts
    87
    Rep Power
    15
    Yeah, it's true that MySQL_fetch_array returns an array and MySQL_fetch_object returns an object

    So now , which one is faster and more efficient ?



    ------------------
    ** It's the world of Oscario **
  8. #5
  9. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    mysql_fetch_row() returns an integer indexed array. mysql_fetch_array() returns an integer indexed and associative array.

    Efficiency is dependent on too many factors to say one is always superior. mysql_fetch_row() is the least processor intensive but the added functionality of fetch_array and fetch_object can more than make up for that if your code is such that it can take advantage of the functionality.

    To my mind mysql_fetch_object is only useful if you are using it to populate properties of an already defined object.

IMN logo majestic logo threadwatch logo seochat tools logo