PHP Designing Interfaces in PHP Introducing Interfaces Implement MySQL RepositoryInterface

There does not seem to be enough information to complete this task - or am I missing something?

We have to implement the all() method of an interface which gets all the data from an SQL table passed to the function but it doesn't say whether this is just a string with the table name or something else. I tried running fetchAll(PDO::FETCH_OBJ) as suggested in the question but it want me to run a query on the database. To do this I believe I need a connection to the database but it doesn't tell me what the connection is or the information I need to establish my own connection.

class sqlRepository extends PDO implements RepositoryInterface
  function all($table)
    $db = 
    $results = $db->query("SELECT * FROM $table");
    return $results->fetchAll(PDO::FETCH_OBJ);

1 Answer

I finally worked out that I could call the PDO functions statically, so this worked:

    $stmt = PDO::query("SELECT * FROM $table");