24

Does anyone know is there is a quick way to get all the records in a table using Doctrine with out using the DQL.

Did I miss something or did you need to just write the public function in the class?

1 Answer 1

53

If you have an entity class (Doctrine Repository manual):

$records = $em->getRepository("Entities\YourTargetEntity")->findAll();

If you don't have entity class (PDO manual):

$pdo = $em->getCurrentConnection()->getDbh();
$result = $pdo->query("select * from table"); //plain sql query here, it's just PDO
$records = $pdo->fetchAll();
3
  • 1
    perfect thanks. The worked. I also found this helpful: symfony.com/doc/2.0/book/doctrine.html Aug 31, 2011 at 0:09
  • Poke: The Doctrine link is no longer valid !
    – RiggsFolly
    Nov 14, 2018 at 11:17
  • 3
    @RiggsFolly Thanks for poking. :) I've fixed the link, but I'd like to point out that SO allows anyone to edit anything. So, since you were concerned about the link and this answer in general, you were probably in a much better position to fix it than me, since I haven't used Doctrine since the link was valid - about 6 or 7 years from now.
    – J0HN
    Nov 15, 2018 at 3:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.