2017-08-04 11 views
1

バックアップからデータを復元するPHPスクリプトに関数があります。突然、何ヶ月もうまく働いてから仕事が止まるまで、すべてうまく動作しました。私はOC 2.2.0を使用しており、この機能は製品とそのデータをoc_product_backupテーブルから復元することになっています。私は、問題がどこにあるか私が見るであろうように、すべてのステップをprint_r、そしてそれが取得するときことに気づい:PHPスクリプトreturn true突然戻り値

return true; 

それが起こることはありません。突然何が間違っているのでしょうか、私はこの仕事をどうやって作っていますか?私はこの種の問題を抱えていませんでした。

function restoreBackup() 
{ 
    global $mysqli; 

    $i    = 0; 
    $getpic   = "SELECT * FROM oc_product_backup LIMIT 0, 100000"; 
    $backup   = $mysqli->query($getpic); 

    $mysqli->autocommit(FALSE); 
    $updateproduct_sql  = "UPDATE oc_product SET image = ?, modified_by = ?, date_modified = ? WHERE product_id= ?"; 
    $updatedescription_sql = "UPDATE oc_product_description SET meta_description = ?, meta_keyword = ?, tag = ?, modified_by = ? WHERE product_id = ? AND language_id = ?"; 

    $stmt = $mysqli->prepare($updateproduct_sql); 
    $stmt->bind_param('siss', $image, $modified_by, $date_modified, $product_id); 
    //print_r ($updateproduct_sql); 
    $stmt2 = $mysqli->prepare($updatedescription_sql); 
    $stmt2->bind_param('sssisi', $meta_description, $meta_keyword, $tag, $modified_by, $product_id, $language_id); 
    //print_r($updatedescription_sql); 

    while($row = $backup->fetch_array(MYSQLI_ASSOC)) 
    { 

     //$name    = removeslashes($row['name']); 
     //$name    = $row['name']; 
     //$description  = removeslashes($row['description']); 
     //$description  = $row['description']; 
     $meta_description = $row['meta_description']; 
     $meta_keyword  = $row['meta_keyword']; 
     $tag    = $row['tag']; 
     $product_id  = $row['product_id']; 
     $modified_by  = $row['modified_by']; 
     $language_id  = $row['language_id']; 
     //if($row['language_id'] == 1) 
     //{ 
     $image   = $row['image']; 
     //$ean   = $row['ean']; 
     //$name   = $row['name']; 
     //$model   = $row['model']; 
     //$status   = $row['status']; 
     $price_sync  = $row['price_sync']; 
     $date_modified = $row['date_modified']; 

     if(!$stmt->execute()) 
      return false; 

     //} 
     if(!$stmt2->execute()) 
      return false; 

     $i++; 
     if(($i % 500) === 0) $mysqli->commit(); 

    } 

    $mysqli->commit(); 
    $backup->close(); //the last line that gets executed 
    return true; //this never happens 
    writeToLog('- Backup restored'); 
} 
+0

データベースのデータが増えたためにスクリプトがタイムアウトしている可能性がありますか? –

+0

@SchalkKeun Thanx(返信用) - 私のDBは当時はそれほど大きくはなかったので、これは問題ではないと思います。とにかく、提案のためのおかげで。 – Nancy

+0

空白のページや[ネットワークのタイムアウト]ページが表示されていますか?このスクリプトは、ブラウザ上で実行されているのか、またはcronジョブとして実行されていますか? –

答えて

0

コードのビットを見た後、それはデータがループの外で結合あなたのプリペアドステートメントのように思えるので、技術的には、任意のデータを書き込んだことはなかっただろう:私の関数はこのようになります。

function restoreBackup() { 
    global $mysqli; 

    $i = 0; 
    $getpic = "SELECT * FROM oc_product_backup LIMIT 0, 100000"; 
    $backup = $mysqli - > query($getpic); 

    $mysqli - > autocommit(FALSE); 
    $updateproduct_sql = "UPDATE oc_product SET image = ?, modified_by = ?, date_modified = ? WHERE product_id= ?"; 
    $updatedescription_sql = "UPDATE oc_product_description SET meta_description = ?, meta_keyword = ?, tag = ?, modified_by = ? WHERE product_id = ? AND language_id = ?"; 


    while ($row = $backup - > fetch_array(MYSQLI_ASSOC)) { 

     $meta_description = $row['meta_description']; 
     $meta_keyword = $row['meta_keyword']; 
     $tag = $row['tag']; 
     $product_id = $row['product_id']; 
     $modified_by = $row['modified_by']; 
     $language_id = $row['language_id']; 
     $image = $row['image']; 
     $price_sync = $row['price_sync']; 
     $date_modified = $row['date_modified']; 

     $stmt = $mysqli - > prepare($updateproduct_sql); 
     $stmt - > bind_param('siss', $image, $modified_by, $date_modified, $product_id); 
     if (!$stmt - > execute()) 
      return false; 

     $stmt2 = $mysqli - > prepare($updatedescription_sql); 
     $stmt2 - > bind_param('sssisi', $meta_description, $meta_keyword, $tag, $modified_by, $product_id, $language_id); 
     if (!$stmt2 - > execute()) 
      return false; 

     $i++; 
     if (($i % 500) === 0) $mysqli - > commit(); 

    } 

    $mysqli - > commit(); 
    $backup - > close(); //the last line that gets executed 
    return true; //this never happens 
    writeToLog('- Backup restored'); 
} 
+0

あなたのソリューションはうまくいくはずですが、単純に解決しません。私は何が起こっているのか分かりません、私は私の心を失っています。 – Nancy

+0

@Nancy、print_r()をどこにでも投げて、すべてのデータが実際に想定どおりに書かれていることを確認することをお勧めします。 –

+0

助けようとするための高齢者。私はprint_r()をすべてやったが、何がうまくいかないかを除いて、すべてうまくいくようだ。私はこれを理解すると、もっと試して答えを投稿します。他に提案がある場合は、教えてください。 – Nancy