Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8302941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:24:25+00:00 2026-06-08T17:24:25+00:00

Typically when I use MySQL in raw PHP I only SELECT the fields I’m

  • 0

Typically when I use MySQL in raw PHP I only SELECT the fields I’m going to be using with that retrieved dataset; in high volume environments it makes sense to reduce the data transfer as much as possible.

It’s cool that Doctrine lets you define related objects so that, by adding a line or two to the entity definition, you can suddenly access Employee->Company->Fax. It seems (though I haven’t checked this) that behind the scenes it’s doing SELECT *. If this is true, is there a way to only pull the fields I think I’ll need? Or do you think it’s even an issue with a solid caching scheme?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:24:26+00:00Added an answer on June 8, 2026 at 5:24 pm

    Doctrine and Entity Manager, in symfony2, act much like as you described.
    As you fetch an object from database, doctrine will do a SELECT * for you.
    Moreover, if you want to access at some related properties via foreign key, doctrine will use the lazy loading that means you haven’t to specify into the query how to retrieve some fields because doctrine alredy knows how. The best thing is that the query isn’t done since you call that field (good in conditional statement and so on)

    Returning to your question, you can retrieve only those fields that you’re interested in. First step is to define a repository for your class object. The second is to write a DQL query (Doctrine Query Language) to extract only “your” fields.

    Here’s an example where I have a class called User and a related repository called UserRepository

    <?php
    namespace CompanyName\UserBundle\Entity;
    
    use Doctrine\ORM\Mapping as ORM;
    use Symfony\Component\Security\Core\User\AdvancedUserInterface;
    use Symfony\Component\Security\Core\User\UserInterface;
    use Doctrine\Common\Collections\ArrayCollection;
    
    /**
     * CompanyName\UserBundle\Entity\User
     *
     * @ORM\Table(name="users")
     * @ORM\Entity(repositoryClass="CompanyName\UserBundle\Repository\UserRepository")
     */
    class User implements AdvancedUserInterface
    {
    [...]
    

    where the “interesting” part is

    @ORM\Entity(repositoryClass="CompanyName\UserBundle\Repository\UserRepository")

    Now the code for repository:

    <?php
    
    namespace CompanyName\UserBundle\Entity;
    
    use Symfony\Component\Security\Core\User\UserInterface;
    use Symfony\Component\Security\Core\User\UserProviderInterface;
    use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
    use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
    use Doctrine\ORM\EntityRepository;
    use Doctrine\ORM\NoResultException;
    
    /**
     * UserRepository
     *
     * This class was generated by the Doctrine ORM. Add your own custom
     * repository methods below.
     */
    class UserRepository extends EntityRepository implements UserProviderInterface
    {
        private $qb = Null;
    
        public function getOrCreateQB()
        {
            if(!$this->qb) {
                $this->qb = $this->createQueryBuilder('u');
            }
            return $this->qb;
        }
        public function loadUserByUsername($username)
        {
           /* some logic */
           /* define $q as the DQL query for column
           that I interested in */
    
           $user = $q->getSingleResult();
    
           return $user;
        }
    [...]
    

    And you got what you want. For use that “custom” query, simply use that repository in the following way

    $userRepo = $this->em->getRepository('SestanteUserBundle:User');
    $this->userRepo->loadUserByUsername('userNameExample');
    

    where, of course, em is an instance of entity manager

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any pre-made scripts that I can use for PHP / MySQL to
I've read that (all things equal) PHP is typically faster than MySQL at arithmetic
Typically I use a database such as MySQL or PostGreSQL on the same machine
I have a typical Flex-based application that was written to use a Java/Hibernate/MySQL backend.
I typically use divs to nest my elements. However, Dustin Diaz mentioned using the
I hope I worded the title accurately enough but I typically use Java and
Typically if we just use alert(object); it will show as [object Object] . How
Typically, I've seen people use the class literal like this: Class<Foo> cls = Foo.class;
I use syntax like name varchar(20) NOT NULL in mysql..i have a big confusion
For my browser based Flex game (for the Facebook platform), I am using PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.