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

<legend id='TImQu'><style id='TImQu'><dir id='TImQu'><q id='TImQu'></q></dir></style></legend>

  • <tfoot id='TImQu'></tfoot>

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

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

        循環內 PDO 語句的綁定參數

        Binding params for PDO statement inside a loop(循環內 PDO 語句的綁定參數)

          <tbody id='9oZyK'></tbody>

          • <bdo id='9oZyK'></bdo><ul id='9oZyK'></ul>
          • <legend id='9oZyK'><style id='9oZyK'><dir id='9oZyK'><q id='9oZyK'></q></dir></style></legend>

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

            • <tfoot id='9oZyK'></tfoot>
            • <small id='9oZyK'></small><noframes id='9oZyK'>

                  本文介紹了循環內 PDO 語句的綁定參數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試在循環內綁定 SQL 查詢的參數:

                  I'm trying to bind parametres for SQL query inside a loop:

                  $db = new PDO('mysql:dbname=test;host=localhost', 'test', '');  
                  $stmt = $db->prepare('INSERT INTO entries VALUES (NULL, ?, ?, ?, NULL)');
                  
                  $title = 'some titile';
                  $post = 'some text';
                  $date = '2010-whatever';  
                  
                  $reindex = array(1 => $title, $post, $date); // indexed with 1 for bindParam
                  
                  foreach ($reindex as $key => $value) {  
                      $stmt->bindParam($key, $value);  
                      echo "$key</br>$value</br>";  //will output: 1</br>some titile</br>2</br>some text</br>3</br>2010-whatever</br>
                  }
                  

                  以上代碼在所有 3 個字段中插入數據庫2010-whatever.

                  The code above inserts in database in all 3 fields 2010-whatever.

                  這個很好用:

                  $stmt->bindParam(1, $title);
                  $stmt->bindParam(2, $post);
                  $stmt->bindParam(3, $date);
                  

                  那么,我的問題是為什么 foreach 循環中的代碼會失敗并在字段中插入錯誤的數據?

                  So, my question is why the code in the foreach-loop fails and inserts wrong data in the fields?

                  推薦答案

                  問題在于 bindParam 需要引用.它將變量綁定到語句,而不是值.由于 foreach 循環中的變量在每次迭代結束時都未設置,因此您不能使用問題中的代碼.

                  The problem is that bindParam requires a reference. It binds the variable to the statement, not the value. Since the variable in a foreach loop is unset at the end of each iteration, you can't use the code in the question.

                  您可以使用 foreach 中的引用執行以下操作:

                  You can do the following, using a reference in the foreach:

                  foreach ($reindex as $key => &$value) {  //pass $value as a reference to the array item
                      $stmt->bindParam($key, $value);  // bind the variable to the statement
                  }
                  

                  或者你可以這樣做,使用 bindValue:

                  Or you could do this, using bindValue:

                  foreach ($reindex as $key => $value) {
                      $stmt->bindValue($key, $value);  // bind the value to the statement
                  }
                  

                  這篇關于循環內 PDO 語句的綁定參數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)

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

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

                          <tfoot id='VWP99'></tfoot>

                          <legend id='VWP99'><style id='VWP99'><dir id='VWP99'><q id='VWP99'></q></dir></style></legend>

                          • 主站蜘蛛池模板: 日韩a级片 | 午夜a级理论片915影院 | 嫩草一区二区三区 | 免费三级网 | 在线日韩福利 | 91不卡| 欧美黑人又粗大 | 欧美久久电影 | 成人黄色在线 | 国产精品亚洲精品日韩已方 | 国产日韩一区二区三区 | 国内精品免费久久久久软件老师 | 91精品国产综合久久小仙女图片 | 一区二区在线不卡 | 欧美成人免费在线 | 国产一级特黄视频 | 日韩中文字幕在线视频 | 日韩欧美视频网站 | 性精品 | 黄色av一区| 五月综合久久 | 欧美精品在线播放 | 精品一区二区av | 欧美视频免费在线观看 | 久久久成人精品 | 欧美午夜激情在线 | 91视频久久| www.久| 欧美一级欧美三级在线观看 | 亚洲精品一区中文字幕乱码 | 成人免费在线观看 | 精品一区二区三区在线播放 | 国产精品久久久久久久久久三级 | 欧美精品一区二区三区在线播放 | 黄视频免费观看 | 精品一二 | 天天射视频| 一区二区不卡视频 | 爱草视频| 欧美a级成人淫片免费看 | 在线观看精品 |