<legend id='g874j'><style id='g874j'><dir id='g874j'><q id='g874j'></q></dir></style></legend>
  • <small id='g874j'></small><noframes id='g874j'>

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

        PDO:无效的参数号:混合命名和位置参数

        时间:2023-09-19
      2. <tfoot id='9xxkv'></tfoot>
            <bdo id='9xxkv'></bdo><ul id='9xxkv'></ul>

              1. <small id='9xxkv'></small><noframes id='9xxkv'>

              2. <i id='9xxkv'><tr id='9xxkv'><dt id='9xxkv'><q id='9xxkv'><span id='9xxkv'><b id='9xxkv'><form id='9xxkv'><ins id='9xxkv'></ins><ul id='9xxkv'></ul><sub id='9xxkv'></sub></form><legend id='9xxkv'></legend><bdo id='9xxkv'><pre id='9xxkv'><center id='9xxkv'></center></pre></bdo></b><th id='9xxkv'></th></span></q></dt></tr></i><div id='9xxkv'><tfoot id='9xxkv'></tfoot><dl id='9xxkv'><fieldset id='9xxkv'></fieldset></dl></div>
                1. <legend id='9xxkv'><style id='9xxkv'><dir id='9xxkv'><q id='9xxkv'></q></dir></style></legend>
                    <tbody id='9xxkv'></tbody>
                  本文介绍了PDO:无效的参数号:混合命名和位置参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我遇到了这个我以前从未见过的警告:

                  I have come across this warning I've not seen before:

                  警告:PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: 无效的参数号:混合命名和位置参数...

                  Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters in...

                  参考下面的PDO查询(为了方便阅读,已经简化了功能):

                  Referring to the following PDO query (have simplified the function for ease of reading):

                  $offset = 0;
                  $limit = 12;
                  function retrieve_search_posts($searchfield, $offset, $limit){
                  
                  
                          $where = array();
                  
                          $words = preg_split('/[s]+/',$searchfield);
                  
                          array_unshift($words, '');
                          unset($words[0]);
                  
                          $where_string = implode(" OR ", array_fill(0,count($words), "`post_title` LIKE ?"));
                  
                          $query = "
                                                  SELECT  p.post_id, post_year, post_desc, post_title, post_date, img_file_name, p.cat_id
                                                  FROM    mjbox_posts p
                                                  JOIN    mjbox_images i
                                                  ON      i.post_id = p.post_id
                                                          AND i.cat_id = p.cat_id
                                                          AND i.img_is_thumb = 1
                                                          AND post_active = 1
                                                  WHERE $where_string
                                                  ORDER BY post_date
                                                  LIMIT :offset, :limit
                                                  DESC";
                          $stmt = $dbh->prepare($query);
                  
                          foreach($words AS $index => $word){
                              $stmt->bindValue($index, "%".$word."%", PDO::PARAM_STR);
                          }
                          $stmt->bindParam(':offset', $offset, PDO::PARAM_INT);
                          $stmt->bindParam(':limit', $limit, PDO::PARAM_INT);
                          $stmt->execute();
                  
                          $searcharray = $stmt->fetchAll(PDO::FETCH_ASSOC);
                  
                          return $searcharray;
                      }
                  

                  函数和 PDO 查询在查询中没有包含偏移量和限制变量的情况下工作正常.那么是什么原因导致了这个警告?

                  The function and PDO query works fine without the offset and limit variables included in the query. So what might be causing this warning?

                  谢谢

                  推荐答案

                  Change

                  LIMIT :offset, :limit
                  

                  LIMIT ?, ?
                  

                  $stmt->bindParam(':offset', $offset, PDO::PARAM_INT);
                  $stmt->bindParam(':limit', $limit, PDO::PARAM_INT);
                  

                  到:

                  $stmt->bindValue($index+1, $offset, PDO::PARAM_INT);
                  $stmt->bindValue($index+2, $limit, PDO::PARAM_INT);
                  

                  这篇关于PDO:无效的参数号:混合命名和位置参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PDO 错误:SQLSTATE[HY000]:一般错误:2031 下一篇:PDO 返回所有行

                  相关文章

                  最新文章

                2. <i id='Xn6gr'><tr id='Xn6gr'><dt id='Xn6gr'><q id='Xn6gr'><span id='Xn6gr'><b id='Xn6gr'><form id='Xn6gr'><ins id='Xn6gr'></ins><ul id='Xn6gr'></ul><sub id='Xn6gr'></sub></form><legend id='Xn6gr'></legend><bdo id='Xn6gr'><pre id='Xn6gr'><center id='Xn6gr'></center></pre></bdo></b><th id='Xn6gr'></th></span></q></dt></tr></i><div id='Xn6gr'><tfoot id='Xn6gr'></tfoot><dl id='Xn6gr'><fieldset id='Xn6gr'></fieldset></dl></div>
                  1. <small id='Xn6gr'></small><noframes id='Xn6gr'>

                  2. <legend id='Xn6gr'><style id='Xn6gr'><dir id='Xn6gr'><q id='Xn6gr'></q></dir></style></legend>

                    • <bdo id='Xn6gr'></bdo><ul id='Xn6gr'></ul>

                      <tfoot id='Xn6gr'></tfoot>