Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 1285 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Doctrine2 using setParameters

#1
when I seem to use parameters in my query, I get an error

> Invalid parameter number: number of bound variables does not match number of tokens

here is my code

<!-- language: lang-php -->

public function GetGeneralRatingWithUserRights($user, $thread_array)
{
$parameters = array(
'thread' => $thread_array['thread'],
'type' => '%'.$thread_array['type'].'%'
);

$dql = 'SELECT p.type,AVG(p.value)
FROM TrackerMembersBundle:Rating p
GROUP BY p.thread,p.type';

$query = $this->em->createQuery($dql)
->setParameters($parameters);

$ratings = $query->execute();

return $ratings;
}

How do I configure the parameters array properly?
Reply

#2
thanks all for your efforts,
i used it differently using the querybuilder


$parameters = array(
'thread' => $thread_array['thread']
,'type' => $thread_array['type']
);


$qb = $this->em->createQueryBuilder();
$query = $qb
->from('TrackerMembersBundle:Rating','rating')
->select(' rating.type,
COUNT(rating.value) AS ratingcount ,
AVG(rating.value) AS ratingaverage ')
->where(
$qb->expr()->orx(
$qb->expr()->eq('rating.thread', ':thread'),
$qb->expr()->like('rating.type', ':type')
)

)
->groupBy('rating.thread,rating.type')
->setParameters($parameters)
->getQuery();
Reply

#3
You didn't include your parameters in the query.

<!-- language: lang-php -->

$parameters = array(
'thread' => $thread_array['thread'],
'type' => '%'.$thread_array['type'].'%'
);

$dql = 'SELECT p.type,AVG(p.value)
FROM TrackerMembersBundle:Rating p
WHERE p.thread=:thread
AND type LIKE :type
GROUP BY p.thread,p.type';

$query = $this->em->createQuery($dql)
->setParameters($parameters);

See examples in the documentation:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through