title: Symfony 2: How to execute sql queries in a service
body: <p>Last week I started working with Symfony 2 and I am bit confused about how to use models and how to create own specific functions.</p>
  
  <p>I have created a service <strong>Testing</strong> in the services.yml file:</p>
  
  <pre><code>services:
  testing:
  class: AppBundle\Service\MyService
   arguments: [ @doctrine.orm.entity_manager ]
  </code></pre>
  
  <p>This is the class MyService</p>
  
  <pre><code>class myService
  {
  
  /**
   * @InjectParams({
   *    "em" = @Inject("doctrine.orm.entity_manager")
   * })
   */
  
  
    public function __construct(EntityManager $em)
    {
    $this-&gt;em = $em;
    }
  
  
    function getQuery($id){
     $sql = "SELECT firstname FROM players WHERE id = $id";
  
      $em = $this-&gt;getDoctrine()-&gt;getManager();
      $stmt = $em-&gt;getConnection()-&gt;prepare($sql);
      $stmt-&gt;execute();
      $players = $stmt-&gt;fetchAll();
  }
  </code></pre>
  
  <p>I would like to execute a query in the service and load the function getQuery() in the controllor like this:</p>
  
  <pre><code>$locationService = $this-&gt;container-&gt;get('testing');
  $ownFunction = $locationService-&gt;getQuery($id);
  </code></pre>
  
  <p>When I execute the script above I get an error.</p>