Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

pdo

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);
like image 216
Braike dp Avatar asked Mar 04 '23 08:03

Braike dp


1 Answers

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

like image 193
Ortomala Lokni Avatar answered Apr 05 '23 21:04

Ortomala Lokni