Welcome Guest, Not a member yet? Register   Sign In
Performance with row()
#1

[eluser]jamie young[/eluser]
Opinions on performance of these two blocks of pseudoish code (assuming PHP5)

Code:
$query = $this->db->query('SELECT * FROM table LIMIT 1');
$row = $query->row();
echo $row->col1;
echo $row->col2;
echo $row->col3;

Code:
$query = $this->db->query('SELECT * FROM table LIMIT 1');
echo $query->row()->col1;
echo $query->row()->col2;
echo $query->row()->col3;

Is there any performance difference at all between the above two blocks of code? I know they both work, just not sure what the long term effects of using one method over the other will have on a large CI project.
#2

[eluser]pistolPete[/eluser]
I bet the first one is faster because you are calling $query->row(); only once.
#3

[eluser]TheFuzzy0ne[/eluser]
I agree. In the first example, the result row is generated three times from the database result.




Theme © iAndrew 2016 - Forum software by © MyBB