There is a function that returns an associative array:

public function getSports(): array { $sql = 'SELECT id, name FROM Sport'; $stmt = $this->connection->prepare($sql); $stmt->execute(); return $stmt->fetchAll(); } 

But besides the id and name fields, there come another 0 and 1 . How to leave only id and name ?

Ps documentation read, like in fetchAll() it is necessary to transfer constants, but did not find what.

  • 3
    PDO::FETCH_ASSOC - Edward

1 answer 1

http://php.net/manual/ru/pdostatement.fetch.php

FETCH_ASSOC: returns an array indexed by the column names of the result set