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

    <bdo id='qkQFb'></bdo><ul id='qkQFb'></ul>

    1. <small id='qkQFb'></small><noframes id='qkQFb'>

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

        如何使用 Zend_Db 添加多于一行?

        How do I add more than one row with Zend_Db?(如何使用 Zend_Db 添加多于一行?)
        1. <small id='8N6st'></small><noframes id='8N6st'>

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

              <legend id='8N6st'><style id='8N6st'><dir id='8N6st'><q id='8N6st'></q></dir></style></legend>
                <bdo id='8N6st'></bdo><ul id='8N6st'></ul>

                • <tfoot id='8N6st'></tfoot>
                    <tbody id='8N6st'></tbody>
                  本文介紹了如何使用 Zend_Db 添加多于一行?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個包含信息的數組,看起來或多或少是這樣的:

                  I have an array with information which looks more or less like this:

                  $data[] = array('content'=>'asd');
                  $data[] = array('content'=>'asdf');
                  

                  我想將兩個條目都添加到數據庫中.

                  And I want to add both entries into the Database.

                  $db->insert('table', $data);
                  

                  不會添加兩個條目.我究竟做錯了什么?我必須使用 Zend_ Db_Table 嗎?

                  does not add both entries. What am I doing wrong? Do I have to use Zend_ Db_Table?

                  $data = array('content'=>'asdf');
                  $db->insert('table', $data);
                  

                  當然有用

                  推薦答案

                  我認為 Zend_Db 不支持插入多行.

                  I don't think Zend_Db supports insertion of multiple rows.

                  但如果你只有兩行或多一點,你可以使用循環.

                  But if you just have two rows or a little more you can just use a loop.

                  foreach ($data as $row)
                  {
                      $db->insert('table', $row)
                  }
                  

                  <小時>Bill Karwin,前 Zend 框架開發人員,撰寫了 不久前在 Nabble 上的這個:


                  Bill Karwin, a former Zend Framework developer, wrote this on Nabble some time ago:

                  行集基本上是一個集合對象,因此我將向該類添加方法以允許將行添加到集合中.所以你應該能夠做到這一點:

                  Rowsets are basically a collection object, so I would add methods to that class to allow rows to be added to the set. So you should be able to do this:

                  // creates a rowset collection with zero rows
                  $rowset = $table->createRowset();
                  
                  // creates one row with unset values 
                  $row = $table->createRow();
                  
                  // adds one row to the rowset 
                  $rowset->addRow($row); 
                  
                  // iterates over the set of rows, calling save() on each row
                  $rowset->save(); 
                  

                  將整數傳遞給 createRowset() 以創建 N 個空行是沒有意義的.無論如何,您只需要遍歷它們即可用值填充它們.因此,您不妨編寫一個循環來使用應用程序數據創建和填充各個行,然后將它們添加到集合中.

                  It makes no sense to pass an integer to createRowset() to create N empty rows. You would just have to iterate through them to populate them with values anyway. So you might as well write a loop to create and populate individual rows with application data, and then add them to the collection.

                  $rowset = $table->createRowset();
                  foreach ($appData as $tuple) 
                  {
                      $row = $table->createRow($tuple);
                      $rowset->addRow($row);
                  }
                  $rowset->save();
                  

                  允許將數組傳遞給 createRowset() 確實有意義,因為這與將元組傳遞給 createRow() 的用法一致.

                  It does make sense to allow an array of arrays to be passed to createRowset(), since this would be consistent with the usage of passing a tuple to createRow().

                  $rowset = $table->createRowset($appData); // pass array of tuples
                  

                  這將執行與上一個示例相同的循環(除了最后的 save()),創建一個新行的新行集,準備進行 save()d.

                  This would perform the same loop as the previous example above (except for the save() at the end), creating a new rowset of new rows, ready to be save()d.

                  SQL中有兩種方法可以提高插入數據的效率:

                  There are two ways in SQL to improve the efficiency of inserting data:

                  1. 對多行使用單個 INSERT 語句:

                  1. Use a single INSERT statement with multiple rows:

                  插入 t (col1, col2, col3) 值 (1, 2, 3), (4, 5, 6), (7, 8, 9);

                  INSERT INTO t (col1, col2, col3) VALUES (1, 2, 3), (4, 5, 6), (7, 8, 9);

                  準備一條 INSERT 語句并多次執行:

                  Prepare an INSERT statement and execute it multiple times:

                  準備插入 t (col1, col2, col3) VALUES (?, ?, ?);執行 1、2、3執行 4、5、6執行 7、8、9

                  PREPARE INSERT INTO t (col1, col2, col3) VALUES (?, ?, ?); EXECUTE 1, 2, 3 EXECUTE 4, 5, 6 EXECUTE 7, 8, 9

                  但是,支持這些改進中的任何一個都會增加 Row 和 Rowset 類的復雜性.這是由于當前 Zend_Db_Table_Row 類在調用 save() 時區分需要插入或更新的行的內部方式.這種區別由 Row 對象封裝,因此 Rowset 不知道各個行是新行還是現有行的修改副本.因此,為了讓 Rowset 類提供使用更高效 SQL 的多行 save() 方法,必須完全重構臟數據的管理.更簡單的解決方案是讓 Rowset 迭代其行,對每一行調用 save().這對于 OO 封裝更好,盡管它無助于優化用于插入行集的 SQL.

                  However, supporting either of these improvements would add complexity to the Row and Rowset classes. This is due to the internal way the current Zend_Db_Table_Row class differentiates between a row that needs to be INSERTed or UPDATEd when you call save(). This distinction is encapsulated by the Row object, so the Rowset doesn't know if the individual rows are new rows or modified copies of existing rows. Therefore for the Rowset class to offer a multi-row save() method that uses more efficient SQL, the management of dirty data would have to be totally refactored. The easier solution is for the Rowset to iterate over its rows, calling save() on each one. This is better for OO encapsulation, though it doesn't help optimize SQL for inserting a rowset.

                  在任何情況下,當最需要高效的 SQL 時,在典型的 Web 請求中批量加載多行數據真的很少見.少量行的效率差異很小,因此只有當您批量加載大量行時,才會有明顯的改進.如果是這種情況,您無論如何都不應該使用 INSERT,您應該使用 MySQL 的 LOAD DATA 語句,或者如果您使用其他 RDBMS 品牌的等效功能.INSERT 通常不是加載大量數據的最有效選擇.

                  In any case, it's really rare to bulk-load many rows of data in a typical web request, when there's the greatest need for efficient SQL. The difference in efficiency for a small number of rows is small, so it would be a noticeable improvement only if you're bulk-loading a huge number of rows. If that's the case, you shouldn't be using INSERT anyway, you should be using MySQL's LOAD DATA statement, or equivalent feature if you use another RDBMS brand. INSERT is not usually the most efficient choice for loading lots of data.

                  關于返回自動生成的密鑰,我不會打擾.請注意,如果您使用純 SQL(例如在 mysql CLI 中),并且在單個 INSERT 語句中插入多行,則只能獲取最后生成的 id 值,而不是所有插入行的 id 值.這是 SQL 行為;它適用于任何語言或任何框架.

                  Regarding returning auto-generated keys, I wouldn't bother. Notice that if you use plain SQL (in the mysql CLI for example), and you insert multiple rows in a single INSERT statement, you can only get the last generated id value, not the id values for all rows inserted. This is SQL behavior; it's true for any language or any framework.

                  INSERT INTO t (col1, col2, col3) VALUES (1, 2, 3), (4, 5, 6), (7, 8, 9);
                  SELECT LAST_INSERT_ID(); -- returns only the id for the third tuple
                  

                  如果您確實需要每一行的 id,您應該編寫一個循環并一次插入一行,在插入每一行后檢索生成的 id.

                  If you do need the id for each row, you should write a loop and insert the rows one at a time, retrieving the generated id after each row inserted.

                  這篇關于如何使用 Zend_Db 添加多于一行?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 找不到驅動程序)

                • <legend id='01mci'><style id='01mci'><dir id='01mci'><q id='01mci'></q></dir></style></legend>
                    • <bdo id='01mci'></bdo><ul id='01mci'></ul>

                          <tfoot id='01mci'></tfoot>

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

                            <small id='01mci'></small><noframes id='01mci'>

                            主站蜘蛛池模板: av中文字幕在线 | 黄色片网此 | 国产一级在线观看 | 日韩欧美精品一区 | 久久久久久久国产精品视频 | 色偷偷噜噜噜亚洲男人 | 国产99久久精品一区二区永久免费 | 国产一区二区三区四区三区四 | 男女视频免费 | 精品国产一区二区三区久久久四川 | 久久精品色欧美aⅴ一区二区 | 久久久涩 | 青青久草 | 网络毛片| 国产精品视频一区二区三区 | 欧美精品久久久久久久久久 | 干干干操操操 | 国产精品成人国产乱一区 | 一区视频在线播放 | 精品一二区 | 久久中文字幕一区 | 国产电影精品久久 | 国产福利在线播放麻豆 | 黄色欧美在线 | 国产午夜精品视频 | 色综合成人网 | 国产在线一区二区 | 91欧美精品成人综合在线观看 | 国产精品久久久精品 | 精品一二区 | 男人的天堂在线视频 | 高清视频一区二区三区 | 亚洲 精品 综合 精品 自拍 | 欧美男人亚洲天堂 | 中文字幕精品视频 | 国产美女自拍视频 | 波多野结衣二区 | 国产福利精品一区 | 国产一区久久 | 欧美一级黄带 | 精品一区视频 |