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

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

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

        <legend id='nRd2W'><style id='nRd2W'><dir id='nRd2W'><q id='nRd2W'></q></dir></style></legend>
      1. 將 PHP while 循環轉換為使用 PDO

        Convert PHP while loop to use PDO(將 PHP while 循環轉換為使用 PDO)

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

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

                <tfoot id='wZ4p5'></tfoot>
                1. 本文介紹了將 PHP while 循環轉換為使用 PDO的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我目前正在通過切換到 PDO 來更新我的應用.我有以下代碼:

                  I'm currently updating my app by switching to PDO. I have the following code:

                  $stmt = $db->prepare("select * from `product` where productid in (:productidLst)");
                  $stmt->bindParam(":productidLst",$productidLst, PDO::PARAM_INT);
                  $stmt->execute();
                  

                  在上面的代碼之后,var $productidLst 是 1,2 我想使用 PDO 等價物:

                  The var $productidLst is 1,2 after the above code I would like to use the PDO equivalent of this:

                  while($rs=mysql_fetch_assoc($res)){
                      $rs['qty']=$_SESSION['basket'][$rs['productid']];
                      $rs['total'] += $rs['qty']*$rs['price'];
                      $total += $rs['total'];
                      $a[] = $rs;
                  }
                  

                  我嘗試了多種組合,但都沒有成功,因此將不勝感激(在第二個代碼塊中,$res 是 sql).其次,我已將參數 $productidLst 設置為 INT 這是正確的還是應該是字符串?

                  I have tried numerous combinations but not been successful so any help with this would be appreciated (in the 2nd code block $res was the sql). Secondly I have set the Parameter $productidLst to INT is this correct or should it be a string?

                  ------------更新 1---------------------------------------------------

                  --------------------UPDATE 1----------------------------------------------------

                  我嘗試了以下代碼:

                  $stmt = $db->prepare("select * from `product` where productid in (:productidLst)");
                  foreach ($stmt->execute(array(':productidLst' => $productidLst)) as $row) 
                  {
                      $total += $row['total'];
                  }
                  

                  返回:為 foreach() 錯誤提供的無效參數

                  Which returns: Invalid argument supplied for foreach() error

                  推薦答案

                  PHP 手冊中的標準文檔通常很有幫助.PHP手冊中有一個用PDO執行for循環的例子,PDO詳情.

                  The standard documentation in the PHP manual is usually pretty helpful. There is an example of executing a for loop with PDO in the PHP manual, PDO Details.

                  function getFruit($conn) {
                      $sql = 'SELECT name, color, calories FROM fruit ORDER BY name';
                      foreach ($conn->query($sql) as $row) {
                          print $row['name'] . "	";
                          print $row['color'] . "	";
                          print $row['calories'] . "
                  ";
                      }
                  }
                  

                  通過一些更改,該示例可以使用準備好的語句.

                  With a few changes, the example can be made to use a prepared statement.

                  function getFruit($conn) {
                      $query = $conn->prepare('SELECT name, color, calories FROM fruit WHERE kind=:kind ORDER BY name');
                      $query->execute(array(':kind' => 'drupe'));
                      // alternatively you could use PDOStatement::fetchAll() and get rid of the loop
                      // this is dependent upon the design of your app
                      foreach ($query as $row) {
                          print $row['name'] . "	";
                          print $row['color'] . "	";
                          print $row['calories'] . "
                  ";
                      }
                  }
                  

                  您還可以使用 while 循環和 PDOStatement::fetch 獲取每一行.

                  You can also use a while loop and PDOStatement::fetch to get each row.

                  function getFruit($conn) {
                      $query = $conn->prepare('SELECT name, color, calories FROM fruit WHERE kind=:kind ORDER BY name');
                      $query->execute(array(':kind' => 'drupe'));
                      // alternatively you could use PDOStatement::fetchAll() and get rid of the loop
                      // this is dependent upon the design of your app
                      while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
                          print $row['name'] . "	";
                          print $row['color'] . "	";
                          print $row['calories'] . "
                  ";
                      }
                  }
                  

                  PHP 手冊在提供創建后兩個版本所需的所有信息方面仍然非常有用.

                  The PHP manual remains quite helpful in providing all the necessary information to create the latter two versions.

                  上一個版本的解釋:假設 $conn 是一個有效的 PDO 對象.$conn->prepare($sql) 返回一個 PDOStatement 對象如果成功,false 失敗 OR 基于您的錯誤處理的異常.因此,假設成功,我們希望實際從對象中獲取數據.我們可以使用 $query->fetch() 在循環或 $query->fetchAll() 獲取依賴于您的應用的數據.傳入類常量 PDO::FETCH_ASSOC 將返回一個數據關聯數組.

                  Explanation of the last version: assuming $conn is a valid PDO object. $conn->prepare($sql) returns a PDOStatement object if successful, false on failure OR an exception based on your error handling. So, assuming success we would want to actually get the data from the object. We can use $query->fetch() in a loop or $query->fetchAll() to get the data dependent upon your app. Passing in the class constant PDO::FETCH_ASSOC will return, you guessed it, an associative array of data.

                  在功能上,foreachwhile 實現是等效的.從概念上講,foreach 更合適,因為 while 循環具有在靜態條件成立時循環的含義,而 foreach 循環遍歷 a 的元素收藏.閱讀一段時間之間的差異PHP 中的循環和 for 循環?" 部分故事.

                  Functionally, the foreach and while implementations are equivalent. Conceptually, a foreach is more appropriate, as a while loop has connotations of looping while a static condition holds, whereas foreach loops over elements of a collection. Read "Differences between a while loop and a for loop in PHP?" for part of the story.

                  請務必閱讀 關于 PDO 的 php.net 參考

                  這篇關于將 PHP while 循環轉換為使用 PDO的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                    <bdo id='ZXzKQ'></bdo><ul id='ZXzKQ'></ul>

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

                        • <legend id='ZXzKQ'><style id='ZXzKQ'><dir id='ZXzKQ'><q id='ZXzKQ'></q></dir></style></legend>

                            <tbody id='ZXzKQ'></tbody>
                          <tfoot id='ZXzKQ'></tfoot>

                            <i id='ZXzKQ'><tr id='ZXzKQ'><dt id='ZXzKQ'><q id='ZXzKQ'><span id='ZXzKQ'><b id='ZXzKQ'><form id='ZXzKQ'><ins id='ZXzKQ'></ins><ul id='ZXzKQ'></ul><sub id='ZXzKQ'></sub></form><legend id='ZXzKQ'></legend><bdo id='ZXzKQ'><pre id='ZXzKQ'><center id='ZXzKQ'></center></pre></bdo></b><th id='ZXzKQ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ZXzKQ'><tfoot id='ZXzKQ'></tfoot><dl id='ZXzKQ'><fieldset id='ZXzKQ'></fieldset></dl></div>
                          1. 主站蜘蛛池模板: 国产精品久久国产精品 | 国产成人精品免费视频大全最热 | 最新国产精品 | 色视频欧美| 伊人网国产 | 一级黄色片网站 | 久草在线在线精品观看 | www.操com | 国产精品久久久久久婷婷天堂 | 久久av一区二区三区 | 二区av| 91看片官网| 自拍视频在线观看 | 精品日韩一区 | 亚洲高清视频一区二区 | 毛片免费看 | 国产xxxx搡xxxxx搡麻豆 | 91精品久久久久 | 久久久久久99 | 欧洲一区二区三区 | 国产一区二区欧美 | 精品视频亚洲 | av二区三区 | 毛片免费观看 | 成年人在线视频 | 欧美a区| 中文字幕视频在线观看免费 | 成人妇女免费播放久久久 | 国产高清精品一区二区三区 | 国产电影一区二区 | 中文字幕一区在线观看视频 | 人人精品 | 日韩一区二区三区在线观看 | 色在线视频网站 | 欧美视频第三页 | 中文日韩在线视频 | 日韩精品免费视频 | 九色综合网 | h片在线观看免费 | 一区二区三区免费 | 欧美精品成人一区二区三区四区 |