<tfoot id='9jciH'></tfoot>

<legend id='9jciH'><style id='9jciH'><dir id='9jciH'><q id='9jciH'></q></dir></style></legend>

      • <bdo id='9jciH'></bdo><ul id='9jciH'></ul>
    1. <i id='9jciH'><tr id='9jciH'><dt id='9jciH'><q id='9jciH'><span id='9jciH'><b id='9jciH'><form id='9jciH'><ins id='9jciH'></ins><ul id='9jciH'></ul><sub id='9jciH'></sub></form><legend id='9jciH'></legend><bdo id='9jciH'><pre id='9jciH'><center id='9jciH'></center></pre></bdo></b><th id='9jciH'></th></span></q></dt></tr></i><div id='9jciH'><tfoot id='9jciH'></tfoot><dl id='9jciH'><fieldset id='9jciH'></fieldset></dl></div>

      <small id='9jciH'></small><noframes id='9jciH'>

      1. 无效的参数号:绑定变量的数量与 Doctrine 中的标记数量不匹配

        时间:2024-08-10

            <tbody id='3NGGq'></tbody>

          <legend id='3NGGq'><style id='3NGGq'><dir id='3NGGq'><q id='3NGGq'></q></dir></style></legend>

            <tfoot id='3NGGq'></tfoot>
          1. <small id='3NGGq'></small><noframes id='3NGGq'>

                <bdo id='3NGGq'></bdo><ul id='3NGGq'></ul>

                  <i id='3NGGq'><tr id='3NGGq'><dt id='3NGGq'><q id='3NGGq'><span id='3NGGq'><b id='3NGGq'><form id='3NGGq'><ins id='3NGGq'></ins><ul id='3NGGq'></ul><sub id='3NGGq'></sub></form><legend id='3NGGq'></legend><bdo id='3NGGq'><pre id='3NGGq'><center id='3NGGq'></center></pre></bdo></b><th id='3NGGq'></th></span></q></dt></tr></i><div id='3NGGq'><tfoot id='3NGGq'></tfoot><dl id='3NGGq'><fieldset id='3NGGq'></fieldset></dl></div>
                  本文介绍了无效的参数号:绑定变量的数量与 Doctrine 中的标记数量不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  使用 Doctrine 2 我想获取一些用户是另一个用户的联系人.user 表包含这些用户之间的映射.函数中的查询会返回如下错误:

                  Using Doctrine 2 I want to get some users that are contacts of another user. The table user contains the mapping between those users. The query in the function will return the following error:

                  参数号无效:绑定变量的数量与标记的数量不匹配.

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

                  但据我所知,$str 设置为b",$ownerId 设置为2",两者均由 setParameters函数.

                  However to my best understanding $stris set to "b" and $ownerId is set to "2" and both are assigned by the setParameters function.

                   protected function getContactBySubstring($str, $ownerId) {
                          echo $str;
                          echo $ownerId;
                          $em = $this->getDoctrine()->getEntityManager();
                          $qb = $em->createQueryBuilder();
                          $qb->add('select', 'u')
                                  ->add('from', 'PastonVerBundleEntityUser u, PastonVerBundleEntityContact c')
                                  ->add('where', "c.owner = ?1 AND c.contact = u.id AND u.username LIKE '?2'")
                                  ->add('orderBy', 'u.firstname ASC, u.lastname ASC')
                                  ->setParameters(array (1=> $ownerId, 2=> '%'.$str.'%'));
                  
                          echo $qb->getDql();
                          $query = $qb->getQuery();
                          $users = $query->getResult();
                          foreach($users as $user)
                              echo $user->getUsername();
                          exit;
                          //return $contacts;
                      }
                  

                  推荐答案

                  不要用引号将查询文本中的任何参数括起来!

                  Don't surround any of the parameters in your query text with quotes!

                  ->add('where', "c.owner = ?1 AND c.contact = u.id AND u.username LIKE '?2'")
                  

                  应该是

                  ->add('where', "c.owner = ?1 AND c.contact = u.id AND u.username LIKE ?2")
                  

                  这篇关于无效的参数号:绑定变量的数量与 Doctrine 中的标记数量不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                      1. <legend id='MbK72'><style id='MbK72'><dir id='MbK72'><q id='MbK72'></q></dir></style></legend>
                          <tfoot id='MbK72'></tfoot>

                        1. <small id='MbK72'></small><noframes id='MbK72'>

                            <tbody id='MbK72'></tbody>