2011-03-09 54 views
-1
Allowed memory size of 134217728 bytes exhausted (tried to allocate 43 bytes) 
Allowed memory size of 134217728 bytes exhausted (tried to allocate 43 bytes) 
Allowed memory size of 134217728 bytes exhausted (tried to allocate 43 bytes) 
Allowed memory size of 134217728 bytes exhausted (tried to allocate 43 bytes) 
Allowed memory size of 134217728 bytes exhausted (tried to allocate 43 bytes) 
Allowed memory size of 134217728 bytes exhausted (tried to allocate 43 bytes) 
Allowed memory size of 134217728 bytes exhausted (tried to allocate 43 bytes) 
+0

嘗試一次將其分成10000塊,您的錯誤似乎說你耗盡內存 - 可能是因爲一次加載了太多數據。 – 2011-03-09 16:05:30

+0

我可以將限制設置爲10000,但它只會節省很多,我沒有得到整個數據 – 2011-03-09 16:10:29

+0

請參閱我的回答解釋我的意思 – 2011-03-09 16:14:16

回答

3

一個CakePHP的實施josh.trow的解決方案:

class DetailsController extends AppController 
{ 
    var $uses = array('Detail','DataDetail'); 

    function import() 
    { 
     $max = $this->Detail->find('count'); 

     $offset = 0; 
     $limit = 10000; 

     do { 
      $exportedData = $importableData = array(); 

      $exportedData = $this->Detail->find('all', array(
       'order' => 'Detail.id', 
       'limit' => $limit, 'offset' => $offset 
      )); 

      foreach($exportedData as $k => $row) { 

       $importableData[] = array('DataDetail'=>array(
        'id' => $row['Detail']['ID'], 
        'name' => $row['Detail']['name'] 
       )); 
      } 

      $this->DataDetail->saveAll($importableData,array('validate'=>false)); 

      $offset += $limit; 

     } while ($offset <= $max); 

     $this->flash(__("The details have been imported.",true)); 
    } 
} 

減少需要來適應你的內存限制$limit大小。您可能還需要在php.ini中增加max_execution_time配置變量,因爲騎行通過1.2M記錄需要一段時間。

NB:我絕對不推薦這種解決方案,除非您需要經常執行此操作並且無需人工干預。

NB2:我要指出的還有那塊蛋糕缺乏能力(原生)在單一INSERT聚集很多行,所以因爲有您的MSSQL數據庫行這個解決方案將針對您的MySQL數據庫進行儘可能多的查詢。對此使用Cake完全沒有必要,我的解決方案應該只是一個概念證明。

+0

Ahhh謝謝你,先生有人誰知道PHP和蛋糕終於到了:) – 2011-03-09 16:43:49

+0

男人你awsomme讓我試試這個我會回覆給你 – 2011-03-09 16:46:30

+0

10000 /小時是不小的數字,所以我想這可以爲他工作,假設它運行速度足夠快(我不明白爲什麼它不會) – 2011-03-09 16:57:50

1

,我會說我不知道​​PHP前言本,所以這絕對是僞代碼:

max = countTotalRows(sourceDB) // COUNT ONLY, DO NOT GET ACTUAL DATA 
base = 0; 
step = 10000; 
do { 
    getRows();     // now you get data - (step) rows of it per loop 
    storeRows();     // and store it 
    base += step; 
} while (base <= max) 

編輯: 從http://www.devdaily.com/php/php-cakephp-database-sql-query-select

$results = $this->Order->query("select * from (your table name) LIMIT (the base), (the step)");

耍賴借用同樣,我不知道Cake或PHP,所以你將不得不做語法等,但這可能會幫助你開始。

+0

以及我怎麼可以做這個蛋糕的方式其不同 – 2011-03-09 16:21:56

+0

非常感謝你的幫助 – 2011-03-09 16:51:36

+0

我盡我所能知道我有什麼。我知道我很欣賞這些,所以這就是我想給人們的。 – 2011-03-09 16:56:37

0

從外觀上看,您只是將一張表導入另一張表,而不會改變數據/結構。只需從Detail表中獲取SQL/CSV轉儲並將其導入到其他數據庫中,然後將其重命名爲DataDetail。

如果DataDetail已經存在,只需使用insert ignore轉儲數據,則可以在phpmyadmin中執行此操作並將其另存爲文件。

+0

我知道這一點。我不想手動執行 – 2011-03-09 16:24:14

+2

在這種情況下,您在CakePHP內部執行操作時會給自己一個巨大的不必要的頭痛和很多額外的負擔。至少在沒有CakePHP的情況下做**。 – Dunhamzzz 2011-03-09 16:44:34

相關問題