<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## 大數據節省內存處理 ### 將查詢數據對象轉成數組   在Laravel框架中,我們可以在使用連貫查詢的時候使用`toArray()`方法將查詢的數據對象轉換成數組,方便使用。   那么在Yii2中,我們可以使用`asArray()`得到同樣的效果。當然,如果查詢的數據量比較大的話這樣做能節省服務器內存,如: ```php $article = Article::find()->asArray()->all(); ``` ### 批量操作數據 #### 批量讀取數據 例如一次性取100條,我們分十次取一次取10條。使用`betch()`進行操作,如下: ```php foreach(Article::find()->betch(10) as $article) { print_r(count($article)); } ``` #### 批量寫入數據 下面是一個將excel數據導入到數據庫的例子,使用`batchInsert()`方法進行數據的寫入,提高效率。 ```php /** * 導入Excel操作 */ public function actionImportExcel() { $inputFile = 'uploads/branches_file.xlsx'; try { $inputFileType = PHPExcel_IOFactory::identify($inputFile); $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($inputFile); } catch (Exception $e) { dir('Error'); } $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); $highestColumn = $sheet->getHighestColumn(); for ($row = 1; $row <= $highestRow; $row++) { $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, null, true, false); if ($row == 1) { continue; } /*$branch = new Branches; $branch->branch_id = $rowData[0][0]; $branch->companies_company_id = $rowData[0][1]; $branch->branch_name = $rowData[0][2]; $branch->branch_address = $rowData[0][3]; $branch->branch_created_date = $rowData[0][4]; $branch->branch_status = $rowData[0][5]; $branch->save();*/ if(!empty($rowData[0][0])){ $data[] = [$rowData[0][0],$rowData[0][1],$rowData[0][2],$rowData[0][3],$rowData[0][4],$rowData[0][5]]; } } Yii::$app->db->createCommand() ->batchInsert('branches', ['branch_id','companies_company_id','branch_name','branch_address','branch_created_date','branch_status'], $data) ->execute(); die('okay'); } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看