O'Reilly logo

Drupal 8 Module Development by Daniel Sipos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling the result

Both of the preceding queries return a StatementInterface, which is traversable. So, to access its data, we can do this:

foreach ($result as $record) {  $id = $record->id;  $team_id = $record->team_id;  $name = $record->name;  $data = $record->data;}

Each item in the loop is a stdClass, and their property names are the actual names of the columns returned, while their values are the column values.

Alternatively, the StatementInterface also has some fetcher methods that can prepare the results for us in different ways. These mostly come from the parent \PDOStatement class, which is native PHP. The simplest is fetchAll():

$records = $result->fetchAll();

This returns an array of stdClass objects as we saw before, so it does all ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required