PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, December 5, 2022

[FIXED] how to access DB from console component application?

 December 05, 2022     doctrine-orm, oci8, php, symfony-2.7     No comments   

Issue

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?.


Solution

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.



Answered By - Vini
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing