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

        <legend id='4BZEk'><style id='4BZEk'><dir id='4BZEk'><q id='4BZEk'></q></dir></style></legend>
          <bdo id='4BZEk'></bdo><ul id='4BZEk'></ul>

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

        <small id='4BZEk'></small><noframes id='4BZEk'>

        帶 PDO 的多個刀片

        Multiple inserts with PDO(帶 PDO 的多個刀片)

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

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

                  <tbody id='mZsE5'></tbody>

                  本文介紹了帶 PDO 的多個刀片的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有數據庫表:imagescategory

                  目前唯一插入到類別表的函數是這樣的:

                  Currently the only function to insert in category table is similar to this:

                  public function add($ttitle)
                  {      
                  try
                      {
                          $stmt = $this->db->prepare("INSERT INTO category (title) VALUES(:title)");
                          $stmt->bindparam(":title",$ttitle);                 
                          $stmt->execute();
                          return true;
                  
                      }
                      catch(PDOException $e)
                      {
                          echo $e->getMessage();  
                          return false;
                      }
                  
                  }
                  

                  我有一個表格可以輸入標題和插入網址圖片的可能性.

                  I have a form to enter title and the possibility of inserting urls images.

                  通過單擊提交標題,我想轉到類別表,到目前為止還可以,圖像應該轉到表圖像,每個圖像都有一個 id,但內部連接到類別的 id.

                  By clicking on the submit the title I want to go to the category table, so far ok, images should go to the table images, an id for each image but with inner join to the id of the category.

                  表格images:

                  id_image | category_id | dir_image
                  

                  我無法正確執行此操作

                  $stmt = $this->db->prepare("INSERT INTO category (title) VALUES(:ttitle)");
                  
                  $stmt = $this->db->prepare("SELECT id_image FROM images WHERE id_category = category_id ");
                  

                  我想要的結果示例:

                  html 表單

                  Category title: Test
                  Image1:   image1.png
                  Image2:   image2.png
                  Image3:   image3.png
                  Image4:   image4.png
                                Submit
                  

                  提交后

                  表格類別:

                   id_category | title
                      1          Test
                  

                  表格圖片:

                   id_image | category_id | dir_image
                      1            1         image1.png
                      2            1         image2.png
                      3            1         image3.png
                      4            1         image4.png
                  

                  <小時>

                  更新:

                  public function add($ttitle,$images)
                  {
                  try {
                          $stmt = $this->db->prepare("INSERT INTO category (title) VALUES(:title)");
                          $stmt->bindparam(":title",$ttitle);                    
                          $stmt->execute();
                  
                          $lastId = $db->lastInsertId();
                  
                         $imgs = count($images);
                         for ($i = 0; $i < $imgs; $i++){
                  
                         $stmt = $this->db->prepare("INSERT INTO images (category_id, dir_image) VALUES (:title)");
                          $stmt->bindparam(":category_id",$lastId); 
                          $stmt->bindparam(":dir_image",$images);
                          $stmt = $this->db->prepare($sql);
                          $stmt->execute()
                  
                          } 
                  
                  
                  
                          return true;
                      }
                      catch(PDOException $e) {
                          echo $e->getMessage();    
                          return false;
                      }
                  
                  }
                  

                  推薦答案

                  幾件事:

                  1. 刪除for循環中的第二個prepare語句
                  2. 在sql語句的VALUES()中添加綁定參數
                  3. 使用 for 循環迭代器或使用 foreach
                  4. 索引 $images 數組
                  1. Remove the second prepare statement inside for loop
                  2. Add binded params into the VALUES() of sql statement
                  3. Index the $images array with for loop iterator or use foreach

                  查看調整后的for循環:

                  $stmt = $this->db->prepare("INSERT INTO images (category_id, dir_image) 
                                              VALUES (:category_id, :dir_image)");
                  
                  $stmt->bindParam(":category_id" ,$lastId); 
                  $stmt->bindParam(":dir_image", $image);
                  for ($i = 0; $i < count($images); $i++){
                      $image = $images[$i];
                      $stmt->execute();
                  } 
                  

                  或者使用 foreach 循環 (假設是一維數組):

                  $stmt = $this->db->prepare("INSERT INTO images (category_id, dir_image) 
                                              VALUES (:category_id, :dir_image)");
                  
                  $stmt->bindParam(":category_id", $lastId); 
                  $stmt->bindParam(":dir_image", $item);
                  foreach ($images as $item){
                      $stmt->execute();
                  } 
                  

                  這篇關于帶 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 找不到驅動程序)
                  <i id='9EYtM'><tr id='9EYtM'><dt id='9EYtM'><q id='9EYtM'><span id='9EYtM'><b id='9EYtM'><form id='9EYtM'><ins id='9EYtM'></ins><ul id='9EYtM'></ul><sub id='9EYtM'></sub></form><legend id='9EYtM'></legend><bdo id='9EYtM'><pre id='9EYtM'><center id='9EYtM'></center></pre></bdo></b><th id='9EYtM'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='9EYtM'><tfoot id='9EYtM'></tfoot><dl id='9EYtM'><fieldset id='9EYtM'></fieldset></dl></div>
                    <legend id='9EYtM'><style id='9EYtM'><dir id='9EYtM'><q id='9EYtM'></q></dir></style></legend>

                        • <bdo id='9EYtM'></bdo><ul id='9EYtM'></ul>

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

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

                            <tfoot id='9EYtM'></tfoot>
                          1. 主站蜘蛛池模板: 日本视频免费观看 | 亚洲一区二区免费视频 | 日韩精品免费看 | 美女视频福利 | 中国特级毛片 | 亚洲免费精品 | 天天视频国产 | 亚洲狠狠干 | 亚洲天堂男人天堂 | 成人h片在线观看 | 国产永久免费视频 | www.四虎在线 | 日本韩国欧美中文字幕 | www.国产.com| 黄色影院在线观看 | 狠狠干狠狠干 | 黄色a一级| 国产三级在线观看视频 | 亚洲国产成人精品女人 | 欧美成人精品一区二区三区在线看 | 伊人av影院 | 一区二区在线免费观看 | 综合色在线 | 国产在线不卡视频 | 香蕉久久久 | 特黄视频| 日韩毛片在线播放 | 日韩久久一区 | 91美女视频 | 日韩欧美在线观看 | 国产精品6 | 97视频国产 | 亚洲综合视频在线观看 | 91手机在线视频 | 一级片在线播放 | 中文字幕日韩欧美 | 国产草草 | 日韩黄网 | 亚洲激情在线 | 中文字幕在线观看网站 | a在线免费观看 |