What does this statement do?

1
while($row = $result->fetch(PDO::FETCH_ASSOC))

I'm following a php tutorial that uses this instruction can anyone explain to me what it does?

    
asked by anonymous 08.05.2016 / 17:35

1 answer

4

Returns a row of the database as an associative array and assigns $row , remembering that the fetch() is executed first and then the assignment.

while($row = $result->fetch(PDO::FETCH_ASSOC))
           2            1        3

1 - The fetch() method returns a row of the database or false if there are no more records, which causes the while to stop.

2 - The assignment of fetch() to a variable is done.

3 - Definition of the type returning, in this case it is an associative array (key / value), could be an object, numeric array etc, see the other types in documentation

More PDO Information

    
08.05.2016 / 17:39