如何从控制台组件应用程序访问数据库?

I am trying to build a batch job using command console and need to connect to DB to fetch data.

I have noticed different methods from different sections to access DB. From controller $this->getDoctrine()->getRepository() is used and for services it is $this->getEntityManager()->getConnection()

what is the way to connect to DB object with console component?.

If You are writing some custom console command I believe that You can just extend it to

Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand

and then just use

$this->getContainer()->get('doctrine')

to be in the right place.