Braike dp
Braike dp

Reputation: 226

What is the difference between fetch() and fetchAll() in PDO query?

I'm confused with using fetch() and fetchAll in a PDO statement. I went through the php.net manual and that made it more confusing. Even went through the suggestions provided in
stackoverflow. If anyone could help me understand it the easy way, it would be great.

For example

    $result = $stmt->fetchAll(PDO::FETCH_OBJ);
    $result = $stmt->fetch(PDO::FETCH_OBJ);

Upvotes: 10

Views: 22746

Answers (1)

Ortomala Lokni
Ortomala Lokni

Reputation: 62466

The documentation says:

PDOStatement::fetch — Fetches the next row from a result set

PDOStatement::fetchAll — Returns an array containing all of the result set rows

Upvotes: 14

Related Questions