2014-04-12 45 views
0

我意外地犯了一個可怕的錯誤,現在我的整個桌子都沒有了。幸運的是,這是我曾經出口過的第一張桌子,所以我有一個備用。但我已出口它爲.php,它採用這種方式出口:如何用數組恢復MySQL表?

$vocabulary = array(
    array('Language' => 'Gotisch','Nederlands' => 'Gotisch','German' => 'Gotisch','English' => 'Gothic','article' => '','id' => '0','type' => '','French' => ''), 
    array('Language' => 'aug´','Nederlands' => 'oog','German' => 'Auge','English' => 'eye','article' => ' ','id' => '0','type' => '','French' => '')) 

有沒有辦法在MySQL中,我可以重新插入?因爲它似乎不是.CSV或.XML,換句話說,我可以將它轉換爲其中一種文件類型嗎?

+0

編寫一個簡短的PHP腳本來插入直接從此工作的數據並不困難。 –

+0

是的,我想用phpMyAdmin恢復它們。但我在哪裏可以找到如何做到這一點?我按下'修理表',但它什麼也沒做。 :S – Blogger

+0

@Blogger你需要從這個php數組中創建一個INSERT語句。什麼是表結構? – user4035

回答

1

難道你不能通過它循環查詢一切嗎?

<?php 
$vocabulary = array(
    array('Language' => 'Gotisch','Nederlands' => 'Gotisch','German' => 'Gotisch','English' => 'Gothic','article' => '','id' => '0','type' => '','French' => ''), 
    array('Language' => 'aug´','Nederlands' => 'oog','German' => 'Auge','English' => 'eye','article' => ' ','id' => '0','type' => '','French' => '')); 

foreach($vocabulary as $word) { 
    $sql = "INSERT INTO tbl (Language, Nederlands, German, English, article, id, type, French) VALUES ('" . $word['Language'] . "', '". $word['Nederlands'] . "', '" . $word['German'] . "', '" . $word['English'] . "', '" . $word['article'] . "', '". $word['id'] . "', '" . $word['type'] . "', '" . $word['French'] . "')"; 
    //query $sql here. also change tbl to your table name 
} 

?> 
+0

耶!它的工作原理:D謝謝,這是最近一次出口,所以現在我沒有那麼多的話。 – Blogger

+0

好吧,我仍然有問題導入錯誤的符號。但我可以通過截斷表格並插入正確的符號來解決這個問題。 – Blogger

+0

@Blogger像什麼? – Shahar

1

這將爲您創建一個CSV文件。

<?php 
$vocabulary = array(
    array('Language' => 'Gotisch','Nederlands' => 'Gotisch','German' => 'Gotisch','English' => 'Gothic','article' => '','id' => '0','type' => '','French' => ''), 
    array('Language' => 'aug´','Nederlands' => 'oog','German' => 'Auge','English' => 'eye','article' => ' ','id' => '0','type' => '','French' => '')); 

$fp = fopen('file.csv', 'w'); 
foreach($vocabulary as $row) 
{ 
    fputcsv($fp, $row); 
} 

fclose($fp); 
?> 
+0

我會稍後嘗試您的解決方案,夏爾也工作過,但你的人也許也很好,知道未來。 – Blogger