久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<small id='Q3qOq'></small><noframes id='Q3qOq'>

    • <bdo id='Q3qOq'></bdo><ul id='Q3qOq'></ul>
    <tfoot id='Q3qOq'></tfoot>

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

      1. 如何忽略 PHP 中準備好的 mysqli 查詢中的參數?

        How to ignore a parameter in a prepared mysqli query in PHP?(如何忽略 PHP 中準備好的 mysqli 查詢中的參數?)
              <bdo id='64fq7'></bdo><ul id='64fq7'></ul>
            • <small id='64fq7'></small><noframes id='64fq7'>

              1. <i id='64fq7'><tr id='64fq7'><dt id='64fq7'><q id='64fq7'><span id='64fq7'><b id='64fq7'><form id='64fq7'><ins id='64fq7'></ins><ul id='64fq7'></ul><sub id='64fq7'></sub></form><legend id='64fq7'></legend><bdo id='64fq7'><pre id='64fq7'><center id='64fq7'></center></pre></bdo></b><th id='64fq7'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='64fq7'><tfoot id='64fq7'></tfoot><dl id='64fq7'><fieldset id='64fq7'></fieldset></dl></div>
                • <legend id='64fq7'><style id='64fq7'><dir id='64fq7'><q id='64fq7'></q></dir></style></legend>
                  <tfoot id='64fq7'></tfoot>

                    <tbody id='64fq7'></tbody>
                  本文介紹了如何忽略 PHP 中準備好的 mysqli 查詢中的參數?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個像這樣準備好的 mysqli 查詢:

                  I have a prepared mysqli query like this:

                  $query = $database->prepare("SELECT * FROM items WHERE inStock > ? AND size < ? AND name LIKE ?");            
                  $query->bind_param('iis', $inStock, $size, $name);              
                  $query->execute();  
                  

                  WHERE 子句中有很多不同的條件可以過濾結果.問題是,這些參數是在搜索表單中提供的,它們不是強制性的.例如,某人可以僅使用名稱進行搜索,或者僅使用尺寸和名稱進行搜索,或者同時使用尺寸、名稱和庫存.

                  There are many various conditions in the WHERE clause which filter out the results. The problem is, that those parameters are supplied in a search form and they aren't mandatory. For example, someone can search by using only the name, or only by using the size and name, or by using the size, name and inStock, all at the same time.

                  我需要某種方式來調整查詢,以便我可以只提供我想要的參數.我能想到的唯一解決方案是制作一個巨大的 if..else 結構,其中存在包含所有搜索選項組合的準備好的查詢,但這是不可能的,因為有數千種組合.

                  I need some way to adjust the query so I can supply only the parameters I want. The only solution I can think of, is to make a huge if..else structure where prepared queries with all combinations of the search options exist, but that is out of the question as there are thousands of combinations.

                  我能想到的唯一實際可行的解決方案是使用未準備好的查詢,我將條件與諸如 $query .= "AND name LIKE '%".escapestuff($_POST['name'])."%'"

                  The only actual realistic solution I can think of, would be to use a not prepared query, where I glue the conditions together with from pieces like $query .= "AND name LIKE '%".escapestuff($_POST['name'])."%'"

                  但這非常難看,我非常希望繼續使用準備好的查詢系統.

                  But that is very ugly and I would very much like to stay with the prepared query system.

                  推薦答案

                  您可以建立一個條件列表并將綁定值和類型添加到列表中,這里是一個快速模型,它使用您的兩個字段參考...

                  You can build up a list of the criteria and add into a list the bind values and types, here is a quick mock up which uses two of the fields you refer to...

                  $data = [];
                  $params = "";
                  $where = [];
                  if ( !empty($name)) {
                      $data[] = $name;
                      $params.="s";
                      $where[] = "name like ?";
                  }
                  if ( !empty($size)) {
                      $data[] = $size;
                      $params.="i";
                      $where[] = "size < ?";
                  }
                  $sql = "SELECT * FROM items";
                  if ( count($where) > 0 ){
                      $sql .= " where ". implode ( " and ", $where);
                  }
                  $query = $database->prepare($sql);
                  $query->bind_param($params, ...$data);
                  $query->execute();
                  

                  請注意,bind_param() 使用 ... 來允許您傳遞數組而不是單個字段.

                  Notice that the bind_param() uses the ... to allow you to pass an array instead of the individual fields.

                  這篇關于如何忽略 PHP 中準備好的 mysqli 查詢中的參數?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  store_result() and get_result() in mysql returns false(mysql 中的 store_result() 和 get_result() 返回 false)
                  Call to undefined function mysqli_result::num_rows()(調用未定義的函數 mysqli_result::num_rows())
                  PHP Prepared Statement Problems(PHP 準備好的語句問題)
                  mysqli_fetch_array returning only one result(mysqli_fetch_array 只返回一個結果)
                  PHP MySQLi Multiple Inserts(PHP MySQLi 多次插入)
                  How do I make sure that values from MySQL keep their type in PHP?(如何確保 MySQL 中的值在 PHP 中保持其類型?)
                      <bdo id='CXpMQ'></bdo><ul id='CXpMQ'></ul>
                        <tbody id='CXpMQ'></tbody>

                        <small id='CXpMQ'></small><noframes id='CXpMQ'>

                          <legend id='CXpMQ'><style id='CXpMQ'><dir id='CXpMQ'><q id='CXpMQ'></q></dir></style></legend>
                          <i id='CXpMQ'><tr id='CXpMQ'><dt id='CXpMQ'><q id='CXpMQ'><span id='CXpMQ'><b id='CXpMQ'><form id='CXpMQ'><ins id='CXpMQ'></ins><ul id='CXpMQ'></ul><sub id='CXpMQ'></sub></form><legend id='CXpMQ'></legend><bdo id='CXpMQ'><pre id='CXpMQ'><center id='CXpMQ'></center></pre></bdo></b><th id='CXpMQ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='CXpMQ'><tfoot id='CXpMQ'></tfoot><dl id='CXpMQ'><fieldset id='CXpMQ'></fieldset></dl></div>
                          <tfoot id='CXpMQ'></tfoot>

                          • 主站蜘蛛池模板: 亚洲www.| 亚洲一区二区精品视频在线观看 | 国产精品永久 | 精品一区国产 | 一区二区高清 | 久久国产精品免费一区二区三区 | 影音av | 日韩中文字幕免费 | 欧美极品一区二区 | 毛片一区二区三区 | jvid精品资源在线观看 | 欧美精品一区二区在线观看 | 国产成人精品视频 | 欧美电影免费观看 | 国产一区二区三区久久久久久久久 | 久久精品中文 | 欧美亚洲一区二区三区 | 噜噜噜噜狠狠狠7777视频 | 国产人成在线观看 | 毛片一级片 | 亚洲最大av网站 | 久久夜色精品国产 | 孕妇一级毛片 | 久久久蜜桃 | 午夜爽爽爽男女免费观看 | 欧美高清视频一区 | 久久国产精品视频 | 亚洲精品区 | 一区二区三区视频在线观看 | 日韩高清电影 | 欧美国产精品一区二区三区 | 超碰成人免费 | 欧美一区二区三区在线观看视频 | 亚洲精品aⅴ | 精品国产伦一区二区三区观看方式 | 精品国产免费一区二区三区五区 | 91视频网址 | 特级做a爱片免费69 精品国产鲁一鲁一区二区张丽 | 久久噜噜噜精品国产亚洲综合 | h免费观看| 国产高清视频在线 |