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

Wednesday, May 11, 2022

[FIXED] How to remove parameters from query builder?

 May 11, 2022     doctrine-orm, mysql, symfony     No comments   

Issue

I have a problem with my query builder. I am using symfony. What i want to acomplish: I have a given query builder, and i want to count all rows based on this query. So i worked on following solution:

$aliases = $queryBuilder->getRootAliases();
$alias = array_values($aliases)[0];

$cloneQueryBuilder = clone $queryBuilder;
$from = $cloneQueryBuilder->getDQLPart('from');

$cloneQueryBuilder->resetDQLParts();

$newQueryBuilder = $cloneQueryBuilder
    ->select('count(' . $alias . '.id)')
    ->add('from', $from[0]);

$this->total = $newQueryBuilder->getQuery()->getSingleScalarResult();

However im getting an exception : Too many parameters: the query defines 0 parameters and you bound 1 Does anyone knows how to solve it ?


Solution

Calling setParameters should overwrite all existing parameters.



Answered By - Joshua
Answer Checked By - Willingham (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