Doctrine 2 - Get all Records

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

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like