result() vs. result_array() ? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12) +--- Thread: result() vs. result_array() ? (/showthread.php?tid=1416) Pages:
1
2
|
result() vs. result_array() ? - suhindra - 03-08-2015 Usually i like to get my result as object thats why i use result mostly. But i want to know which is the better approach that i should follow, Which one of them is more efficient to use in regards to performance? Here is the Example i am talking about: Code: $query = $this->db->get(); or is this should be the better?? Code: $query = $this->db->get(); Thank you. RE: result() vs. result_array() ? - Narf - 03-09-2015 It doesn't matter. RE: result() vs. result_array() ? - gcdsm12 - 03-09-2015 Both are good however when you use result_array() it makes the query and places it in an array and when you use result() it puts the query in a stdClass object there are these two forms because you can not return a stdClass object in a method only in the array. Sorry my english poor! RE: result() vs. result_array() ? - spjonez - 03-15-2015 Doesn't matter, it's up to developers preference on working with the data. I prefer array's as merging is easier but a lot of dev's prefer objects for their syntax. RE: result() vs. result_array() ? - sajid19991 - 03-15-2015 as others have said, it doesn't matter, it depends on personal choice and personal taste of syntax... however if you are merging your results then you should prefer result_array(), but like me if you are using ci's inbuilt template parser then you should prefer result().. RE: result() vs. result_array() ? - RobertSF - 03-15-2015 Yes, it's mostly a matter of personal preference. RE: result() vs. result_array() ? - suhindra - 03-15-2015 thanks guys if It doesn't matter. right now i will still using result() in my generic model. RE: result() vs. result_array() ? - kilishan - 03-16-2015 For all practical reasons I agree with everyone else - it doesn't matter. There is a very slight performance edge using objects, since they don't require the extra memory allocation that an array uses, but objects are much less flexible. And optimizing this at the point of your development that any of use probably in? A waste of time. Me - I have a tendency to use objects when I can, simply because I prefer the syntax. The more I work with complex applications, though, the more I standardize on arrays since there are so many useful functions in PHP for arrays. RE: result() vs. result_array() ? - attrox - 03-18-2015 What about when passed as parameters on a function call? What is the best practice for implementing the function? function doSomething($data_array) or function doSomething($object)? RE: result() vs. result_array() ? - RobertSF - 03-18-2015 I'd also say that's a matter of personal preference. |