1

his is not working can anyone help please?

(count($stmt->fetchAll()) > 1) ? $result = $stmt->fetchAll() : $result = $stmt->fetch();

print_r($result);
Mureinik
  • 297,002
  • 52
  • 306
  • 350
Abdul Moiz
  • 1,317
  • 2
  • 17
  • 40

1 Answers1

2

All the fetchXYZ methods advance the underlying cursor, so once you've called them, you cannot "go back" and get the same rows again.

You could redo your condition in-memory, after calling fetchAll() only once:

$result = $statement->fetchAll();
if (count($result) == 1) {
    $result = $result[0];
}
Mureinik
  • 297,002
  • 52
  • 306
  • 350