What does this instruction do?

Asked

Viewed 92 times

1

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

I am following a php tutorial that uses this instruction someone can explain me what it does?

1 answer

4


Returns a database row as an associative array and assigns to $row, recalling that the fetch() and then the assignment.

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

1 - The method fetch() returns a row from the database or false if there are no more records, what makes the while stop.

2 - The assignment of fetch() in a variable.

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

More information about PDO

Browser other questions tagged

You are not signed in. Login or sign up in order to post.