Welcome Guest, Not a member yet? Register   Sign In
result() or result_array() ?
#1

[eluser]smoku[/eluser]
Is it better to return $query->result() or $query->result_array() from model?

I think that if we use $var = $query->result_array() the table is copied, and if we use object $var = $query->result() then it is only linked (reference).
#2

[eluser]ekeretex[/eluser]
Assuming they call mysql_fetch_array and mysql_fetch_object behind the scenes (assuming the database is MySQL), the performance is identical.

It's just a matter of preference, but if you're using objects in the rest of your code, you might as well be consistent.
#3

[eluser]tonanbarbarian[/eluser]
for personal preference i use result_array
I prefer to keep my data as arrays rather than objects so it is easier to distinguish from the controller and other objects and libraries and such

from a coding point of view it does not matter which is used except possibly when performing actions on the results.
I do know that working with objects is sometimes a little slower than working with arrays (or used to be in versions of PHP4)
for instance
Code:
$obj =& new stdClass();
is slower than
Code:
$obj=array();
but can be considered similar in that they create an empty construct to work with
also adding properties to an object is supposed to be slower than adding items to an array. This assumes that the property of the object did not exists in the class definition.

However unless you are working with huge amounts of objects or array in a single request you will not see much difference whether you use arrays or objects




Theme © iAndrew 2016 - Forum software by © MyBB