allex01 Posted February 29, 2008 Share Posted February 29, 2008 What is the difference between mysql_fetch_assoc() and mysql_fetch_object() Link to comment https://forums.phpfreaks.com/topic/93781-mysql_fetch_object/ Share on other sites More sharing options...
Ads Posted March 1, 2008 Share Posted March 1, 2008 http://au2.php.net/mysql_fetch_assoc http://au2.php.net/mysql_fetch_object Link to comment https://forums.phpfreaks.com/topic/93781-mysql_fetch_object/#findComment-480540 Share on other sites More sharing options...
allex01 Posted March 1, 2008 Author Share Posted March 1, 2008 I did read the links you provided but still not sure of the difference. Here's what they say mysql_fetch_object() is similar to mysql_fetch_array(), with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names). Well What is the difference between object and array. They mention is mysql_fetch_object() can only access data by field name. Isn't that the same for mysql_fetch_assoc(). How do they differ. Link to comment https://forums.phpfreaks.com/topic/93781-mysql_fetch_object/#findComment-480542 Share on other sites More sharing options...
Ads Posted March 1, 2008 Share Posted March 1, 2008 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] I prefer using an Array. But that is Just me Link to comment https://forums.phpfreaks.com/topic/93781-mysql_fetch_object/#findComment-480547 Share on other sites More sharing options...
trq Posted March 1, 2008 Share Posted March 1, 2008 If you don't know what an object is you have no used for mysql_fetch_object at this point in time. if you'd like to find out what objects are, have a read of the OOP5 section of the manual. Link to comment https://forums.phpfreaks.com/topic/93781-mysql_fetch_object/#findComment-480549 Share on other sites More sharing options...
allex01 Posted March 1, 2008 Author Share Posted March 1, 2008 Can you briefly explain what is the purpose or advantages of using classes and objects in php compared to just using stand alone functions. Link to comment https://forums.phpfreaks.com/topic/93781-mysql_fetch_object/#findComment-480613 Share on other sites More sharing options...
trq Posted March 1, 2008 Share Posted March 1, 2008 Can you briefly explain what is the purpose or advantages of using classes and objects in php compared to just using stand alone functions. No, sorry, but a brief explination would be near on impossible. Once you start using classes/objects and then get further into design patterns things will start to click, but without that experience the question 'what is the purpose or advantages of using classes and objects in php compared to just using stand alone functions' will still make sense. Link to comment https://forums.phpfreaks.com/topic/93781-mysql_fetch_object/#findComment-480616 Share on other sites More sharing options...
trq Posted March 1, 2008 Share Posted March 1, 2008 ps: Some have tried to answer the question here but really, untill you have the understanding, its pretty hard to grasp/believe that OOP can be of much benifit. Link to comment https://forums.phpfreaks.com/topic/93781-mysql_fetch_object/#findComment-480618 Share on other sites More sharing options...
allex01 Posted March 1, 2008 Author Share Posted March 1, 2008 That's the confusing part, If no one can really explains it, it's really hard to understand the great advantage over just using plain functions. Link to comment https://forums.phpfreaks.com/topic/93781-mysql_fetch_object/#findComment-480624 Share on other sites More sharing options...
MikeL Posted March 1, 2008 Share Posted March 1, 2008 The famous analogy is an Object is like a cat. it can do things like meow and sleep and also it can have properties like color and weight at the same time. OOP is more 'black box' like. you really don't _need_ to know it. Link to comment https://forums.phpfreaks.com/topic/93781-mysql_fetch_object/#findComment-480627 Share on other sites More sharing options...
allex01 Posted March 1, 2008 Author Share Posted March 1, 2008 And so does the dog. I don't think i understand your cat analogy or the relavence. There have to be a purpose for using objects. Otherwise it wouldn't be an option. Link to comment https://forums.phpfreaks.com/topic/93781-mysql_fetch_object/#findComment-480665 Share on other sites More sharing options...
trq Posted March 1, 2008 Share Posted March 1, 2008 There is a purpose, did you read the thread at the link provided? Link to comment https://forums.phpfreaks.com/topic/93781-mysql_fetch_object/#findComment-480669 Share on other sites More sharing options...
allex01 Posted March 1, 2008 Author Share Posted March 1, 2008 I did. Seems like everything the object have to offer i can just do using functions. I don't understand the advantage. A simple example would help. Link to comment https://forums.phpfreaks.com/topic/93781-mysql_fetch_object/#findComment-480674 Share on other sites More sharing options...
trq Posted March 1, 2008 Share Posted March 1, 2008 Thats the thing, there is no such thing as a simple example that would explain the benifits properly. Link to comment https://forums.phpfreaks.com/topic/93781-mysql_fetch_object/#findComment-480678 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.