pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="kio8c0a" 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="ccacimq" 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="o4wmuae" id='CXpMQ'><tfoot id='CXpMQ'></tfoot><dl id='CXpMQ'><fieldset id='CXpMQ'></fieldset></dl></div>
                          <tfoot id='CXpMQ'></tfoot>

                          • 主站蜘蛛池模板: 雷冲击高压发生器-水内冷直流高压发生器-串联谐振分压器-武汉特高压电力科技有限公司 | 不锈钢监控杆_监控立杆厂家-廊坊耀星光电科技有限公司 | 临朐空调移机_空调维修「空调回收」临朐二手空调 | 方源木业官网-四川木门-全国木门专业品牌 | 玻璃钢格栅盖板|玻璃钢盖板|玻璃钢格栅板|树篦子-长沙川皖玻璃钢制品有限公司 | SRRC认证_电磁兼容_EMC测试整改_FCC认证_SDOC认证-深圳市环测威检测技术有限公司 | 北京晚会活动策划|北京节目录制后期剪辑|北京演播厅出租租赁-北京龙视星光文化传媒有限公司 | TPM咨询,精益生产管理,5S,6S现场管理培训_华谋咨询公司 | 医学模型生产厂家-显微手术模拟训练器-仿真手术模拟训练系统-北京医教科技 | 滑石粉,滑石粉厂家,超细滑石粉-莱州圣凯滑石有限公司 | 砂尘试验箱_淋雨试验房_冰水冲击试验箱_IPX9K淋雨试验箱_广州岳信试验设备有限公司 | 重庆波纹管|重庆钢带管|重庆塑钢管|重庆联进管道有限公司 | 全自动五线打端沾锡机,全自动裁线剥皮双头沾锡机,全自动尼龙扎带机-东莞市海文能机械设备有限公司 | 沥青车辙成型机-车托式混凝土取芯机-混凝土塑料试模|鑫高仪器 | 美名宝起名网-在线宝宝、公司、起名平台 | 无锡门窗-系统门窗-阳光房-封阳台-断桥铝门窗厂[窗致美] | 精雕机-火花机-精雕机 cnc-高速精雕机-电火花机-广东鼎拓机械科技有限公司 | 赛尔特智能移动阳光房-阳光房厂家-赛尔特建筑科技(广东)有限公司 | SMC-ASCO-CKD气缸-FESTO-MAC电磁阀-上海天筹自动化设备官网 | 超声波清洗机_超声波清洗机设备_超声波清洗机厂家_鼎泰恒胜 | 北京公积金代办/租房发票/租房备案-北京金鼎源公积金提取服务中心 | 北京网站建设首页,做网站选【优站网】,专注北京网站建设,北京网站推广,天津网站建设,天津网站推广,小程序,手机APP的开发。 | 赛默飞Thermo veritiproPCR仪|ProFlex3 x 32PCR系统|Countess3细胞计数仪|371|3111二氧化碳培养箱|Mirco17R|Mirco21R离心机|仟诺生物 | 变色龙云 - 打包app_原生app_在线制作平台_短链接_ip查询 | 泡沫消防车_水罐消防车_湖北江南专用特种汽车有限公司 | 金刚网,金刚网窗纱,不锈钢网,金刚网厂家- 河北萨邦丝网制品有限公司 | 奇酷教育-Python培训|UI培训|WEB大前端培训|Unity3D培训|HTML5培训|人工智能培训|JAVA开发的教育品牌 | 踏板力计,制动仪,非接触多功能速度仪,逆反射系数测试仪-创宇 | 24位ADC|8位MCU-芯易德科技有限公司 | 礼仪庆典公司,礼仪策划公司,庆典公司,演出公司,演艺公司,年会酒会,生日寿宴,动工仪式,开工仪式,奠基典礼,商务会议,竣工落成,乔迁揭牌,签约启动-东莞市开门红文化传媒有限公司 | 蓄电池回收,ups电池后备电源回收,铅酸蓄电池回收,机房电源回收-广州益夫铅酸电池回收公司 | 北京自然绿环境科技发展有限公司专业生产【洗车机_加油站洗车机-全自动洗车机】 | 杭州货架订做_组合货架公司_货位式货架_贯通式_重型仓储_工厂货架_货架销售厂家_杭州永诚货架有限公司 | 天津市能谱科技有限公司-专业的红外光谱仪_红外测油仪_紫外测油仪_红外制样附件_傅里叶红外光谱技术生产服务厂商 | 冷藏车厂家|冷藏车价格|小型冷藏车|散装饲料车厂家|程力专用汽车股份有限公司销售十二分公司 | 存包柜厂家_电子存包柜_超市存包柜_超市电子存包柜_自动存包柜-洛阳中星 | 南京蜂窝纸箱_南京木托盘_南京纸托盘-南京博恒包装有限公司 | NM-02立式吸污机_ZHCS-02软轴刷_二合一吸刷软轴刷-厦门地坤科技有限公司 | UV固化机_UVLED光固化机_UV干燥机生产厂家-上海冠顶公司专业生产UV固化机设备 | 语料库-提供经典范文,文案句子,常用文书,您的写作得力助手 | 礼仪庆典公司,礼仪策划公司,庆典公司,演出公司,演艺公司,年会酒会,生日寿宴,动工仪式,开工仪式,奠基典礼,商务会议,竣工落成,乔迁揭牌,签约启动-东莞市开门红文化传媒有限公司 |