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

    <bdo id='9gjox'></bdo><ul id='9gjox'></ul>

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

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

        如何使用 mysqli 編寫一個安全的 SELECT 查詢,該查

        How to write a secure SELECT query which has a variable number of user-supplied values with mysqli?(如何使用 mysqli 編寫一個安全的 SELECT 查詢,該查詢具有可變數量的用戶提供的值?) - IT屋-程序員軟件開發技術

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

              <tbody id='JKAlt'></tbody>
              • <bdo id='JKAlt'></bdo><ul id='JKAlt'></ul>
              • <small id='JKAlt'></small><noframes id='JKAlt'>

                  本文介紹了如何使用 mysqli 編寫一個安全的 SELECT 查詢,該查詢具有可變數量的用戶提供的值?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我需要一些幫助,以便在我的代碼中執行 foreach.

                  I would like some help to execute a foreach into my code.

                  我將多個值發布到用戶名中:作為 username[0] = user1 , user2

                  I post multiple value into username : as username[0] = user1 , user2

                  但是我的 foreach 給我的結果只是最后一個條目或什么都沒有.

                  but my foreach gives me result like only the last entry or nothing.

                  $companyname = $_POST['companyname'];
                  $username_grab = $_POST['username'];
                  $username = implode(",", $username_grab);
                  
                  foreach ($username_grab as $value){
                      $value = $username_grab;
                  
                      $sql = "select * from linked_user where username = '$value' and company_name = '$companyname'";
                      $res = mysqli_query($conn,$value);
                      while($row = mysqli_fetch_array($res)){
                          $returnValue['username'] = $row['username'];
                          $returnValue['user_scid'] = $row['user_scid'];
                      }
                  }
                  echo json_encode($returnValue);
                  ?>
                  

                  推薦答案

                  您要執行的任務是帶有可變數量占位符的準備好的語句.這在 PDO 中更簡單,但我將向您展示 mysqli 面向對象風格的方法.不管怎樣,總是打印一個 json 編碼的數組,這樣你的接收腳本就知道需要什么樣的數據類型.

                  The task you are to perform is a prepared statement with a variable number of placeholders. This is simpler in PDO, but I'll show you the mysqli object-oriented style approach. No matter what, always print a json encoded array so that your receiving script knows what kind of data type to expect.

                  我有一個片段,其中包括一整套診斷和錯誤檢查.我沒有測試過這個腳本,但它與我的這篇文章非常相似.

                  I had a snippet laying around that includes a full battery of diagnostics and error checking. I have not tested this script, but it has quite the resemblance to this post of mine.

                  if (empty($_POST['companyname']) || empty($_POST['username'])) {  // perform any validations here before doing any other processing
                      exit(json_encode([]));
                  }
                  
                  $config = ['localhost', 'root', '', 'dbname'];  // your connection credentials or use an include file
                  $values = array_merge([$_POST['companyname']], explode(',', $_POST['username']));  // create 1-dim array of dynamic length
                  $count = sizeof($values);
                  $placeholders = implode(',', array_fill(0, $count - 1, '?'));  // -1 because companyname placeholder is manually written into query
                  $param_types = str_repeat('s', $count);
                  if (!$conn = new mysqli(...$config)) {
                      exit(json_encode("MySQL Connection Error: <b>Check config values</b>"));  // $conn->connect_error
                  }
                  if (!$stmt = $conn->prepare("SELECT user_scid, user_scid FROM linked_user WHERE company_name = ? AND username IN ({$placeholders})")) {
                      exit(json_encode("MySQL Query Syntax Error: <b>Failed to prepare query</b>"));  // $conn->error
                  }
                  if (!$stmt->bind_param($param_types, ...$values)) {
                      exit(json_encode("MySQL Query Syntax Error: <b>Failed to bind placeholders and data</b>"));  // $stmt->error;
                  }
                  if (!$stmt->execute()) {
                      exit(json_encode("MySQL Query Syntax Error: <b>Execution of prepared statement failed.</b>"));  // $stmt->error;
                  }
                  if (!$result = $stmt->get_result()) {
                      exit(json_encode("MySQL Query Syntax Error: <b>Get Result failed.</b>")); // $stmt->error;
                  }
                  exit(json_encode($result->fetch_all(MYSQLI_ASSOC)));
                  

                  如果您不想要所有這些診斷條件和評論的膨脹,這里是應該執行相同的基本等效:

                  If you don't want the bloat of all of those diagnostic conditions and comments, here is the bare bones equivalent which should perform identically:

                  if (empty($_POST['companyname']) || empty($_POST['username'])) {
                      exit(json_encode([]));
                  }
                  
                  $values = explode(',', $_POST['username']);
                  $values[] = $_POST['companyname'];
                  $count = count($values);
                  $placeholders = implode(',', array_fill(0, $count - 1, '?'));
                  $param_types = str_repeat('s', $count);
                  
                  $conn = new mysqli('localhost', 'root', '', 'dbname');
                  $stmt = $conn->prepare("SELECT user_scid, user_scid FROM linked_user WHERE username IN ({$placeholders}) AND company_name = ?");
                  $stmt->bind_param($param_types, ...$values);
                  $stmt->execute();
                  $result = $stmt->get_result();
                  exit(json_encode($result->fetch_all(MYSQLI_ASSOC)));
                  

                  這篇關于如何使用 mysqli 編寫一個安全的 SELECT 查詢,該查詢具有可變數量的用戶提供的值?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 中保持其類型?)
                  <tfoot id='oB2iE'></tfoot>

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

                    <tbody id='oB2iE'></tbody>
                    <bdo id='oB2iE'></bdo><ul id='oB2iE'></ul>

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

                            主站蜘蛛池模板: 日韩欧美视频 | 久久机热| 午夜资源 | 九九热在线视频 | 久久一区视频 | 免费观看的黄色网址 | 国外成人在线视频 | .国产精品成人自产拍在线观看6 | 欧美三区| 毛片网站在线观看视频 | 精品国产乱码久久久久久蜜退臀 | 国产91精品久久久久久久网曝门 | 一级片网址 | 国产精品免费一区二区三区四区 | 野狼在线社区2017入口 | 一区二区三区视频在线 | 久久九九网站 | 精品欧美乱码久久久久久 | www国产亚洲精品久久网站 | 国产一二区视频 | 国产成人免费在线 | 国产一级特黄aaa大片评分 | 中文字幕在线第一页 | www中文字幕 | 国产精品毛片在线 | 亚洲视频免费 | 成人伊人 | 在线亚洲欧美 | 精品成人69xx.xyz | 欧美伊人久久久久久久久影院 | 日本欧美国产在线 | 国产精品1区2区3区 欧美 中文字幕 | 精品日韩在线 | 欧美日韩精品中文字幕 | 午夜久久久 | 亚洲男人的天堂网站 | 成人精品国产免费网站 | 亚洲久草| 国产激情视频在线观看 | 在线成人精品视频 | 欧美成人在线影院 |