<small id='4FyOo'></small><noframes id='4FyOo'>

        <legend id='4FyOo'><style id='4FyOo'><dir id='4FyOo'><q id='4FyOo'></q></dir></style></legend>

        • <bdo id='4FyOo'></bdo><ul id='4FyOo'></ul>
        <tfoot id='4FyOo'></tfoot>

        <i id='4FyOo'><tr id='4FyOo'><dt id='4FyOo'><q id='4FyOo'><span id='4FyOo'><b id='4FyOo'><form id='4FyOo'><ins id='4FyOo'></ins><ul id='4FyOo'></ul><sub id='4FyOo'></sub></form><legend id='4FyOo'></legend><bdo id='4FyOo'><pre id='4FyOo'><center id='4FyOo'></center></pre></bdo></b><th id='4FyOo'></th></span></q></dt></tr></i><div id='4FyOo'><tfoot id='4FyOo'></tfoot><dl id='4FyOo'><fieldset id='4FyOo'></fieldset></dl></div>

        如何将 WHERE IN 与 Doctrine 2 一起使用

        How to use WHERE IN with Doctrine 2(如何将 WHERE IN 与 Doctrine 2 一起使用)

        <legend id='n2Rd4'><style id='n2Rd4'><dir id='n2Rd4'><q id='n2Rd4'></q></dir></style></legend>
            <bdo id='n2Rd4'></bdo><ul id='n2Rd4'></ul>

          • <small id='n2Rd4'></small><noframes id='n2Rd4'>

                <i id='n2Rd4'><tr id='n2Rd4'><dt id='n2Rd4'><q id='n2Rd4'><span id='n2Rd4'><b id='n2Rd4'><form id='n2Rd4'><ins id='n2Rd4'></ins><ul id='n2Rd4'></ul><sub id='n2Rd4'></sub></form><legend id='n2Rd4'></legend><bdo id='n2Rd4'><pre id='n2Rd4'><center id='n2Rd4'></center></pre></bdo></b><th id='n2Rd4'></th></span></q></dt></tr></i><div id='n2Rd4'><tfoot id='n2Rd4'></tfoot><dl id='n2Rd4'><fieldset id='n2Rd4'></fieldset></dl></div>
                • <tfoot id='n2Rd4'></tfoot>
                    <tbody id='n2Rd4'></tbody>
                • 本文介绍了如何将 WHERE IN 与 Doctrine 2 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有以下代码,这给了我错误:

                  I have the following code which gives me the error:

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

                  代码:

                  public function getCount($ids, $outcome)
                  {
                      if (!is_array($ids)) {
                          $ids = array($ids);
                      }
                      $qb = $this->getEntityManager()->createQueryBuilder();
                      $qb->add('select', $qb->expr()->count('r.id'))
                         ->add('from', 'MyEntityRating r');
                      if ($outcome === 'wins') { 
                          $qb->add('where', $qb->expr()->in('r.winner', array('?1')));
                      }
                      if ($outcome === 'fails') {
                          $qb->add('where', $qb->expr()->in('r.loser', array('?1')));
                      }
                      $qb->setParameter(1, $ids);
                      $query = $qb->getQuery();
                      //die('q = ' . $qb);
                      return $query->getSingleScalarResult();
                  }
                  

                  数据(或 $ids):

                  Data (or $ids):

                  Array
                  (
                      [0] => 566
                      [1] => 569
                      [2] => 571
                  )
                  

                  DQL 结果:

                  q = SELECT COUNT(r.id) FROM MyEntityRating r WHERE r.winner IN('?1')
                  

                  推荐答案

                  在研究这个问题时,我发现了一些对于遇到同样问题并寻求解决方案的人来说很重要的东西.

                  In researching this issue, I found something that will be important to anyone running into this same issue and looking for a solution.

                  从原来的帖子,下面这行代码:

                  From the original post, the following line of code:

                  $qb->add('where', $qb->expr()->in('r.winner', array('?1')));
                  

                  将命名参数包装为数组会导致绑定参数编号问题.通过从它的数组包装中删除它:

                  Wrapping the named parameter as an array causes the bound parameter number issue. By removing it from its array wrapping:

                  $qb->add('where', $qb->expr()->in('r.winner', '?1'));
                  

                  应该修复这个问题.这可能是 Doctrine 以前版本中的一个问题,但在 2.0 的最新版本中已修复.

                  This issue should be fixed. This might have been a problem in previous versions of Doctrine, but it is fixed in the most recent versions of 2.0.

                  这篇关于如何将 WHERE IN 与 Doctrine 2 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)

                    <legend id='LQwlO'><style id='LQwlO'><dir id='LQwlO'><q id='LQwlO'></q></dir></style></legend>
                  1. <small id='LQwlO'></small><noframes id='LQwlO'>

                    <i id='LQwlO'><tr id='LQwlO'><dt id='LQwlO'><q id='LQwlO'><span id='LQwlO'><b id='LQwlO'><form id='LQwlO'><ins id='LQwlO'></ins><ul id='LQwlO'></ul><sub id='LQwlO'></sub></form><legend id='LQwlO'></legend><bdo id='LQwlO'><pre id='LQwlO'><center id='LQwlO'></center></pre></bdo></b><th id='LQwlO'></th></span></q></dt></tr></i><div id='LQwlO'><tfoot id='LQwlO'></tfoot><dl id='LQwlO'><fieldset id='LQwlO'></fieldset></dl></div>
                      <tfoot id='LQwlO'></tfoot>
                        <tbody id='LQwlO'></tbody>
                        <bdo id='LQwlO'></bdo><ul id='LQwlO'></ul>