2016-06-20 8 views
0

私はOpencart v2.2.0を使用しており、私のPHPスクリプトに問題があります。問題の行は次のとおりです。私のPHPスクリプトで致命的なエラーが発生しました

 $stmt2->bind_param('sssssisi', $name, $description, $meta_description, $meta_keyword, $tag, $modified_by, $product_id, $language_id); 

次のように上記の行を含めた全体の機能は次のとおりです。

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 = ?, ean = ?, model = ?, status = ?, price_sync = ?, modified_by = ?, date_modified = ? WHERE product_id= ?"; 
    $updatedescription_sql = "UPDATE oc_product_description SET name = ?, description = ?, meta_description = ?, meta_keyword = ?, tag = ?, modified_by = ? WHERE product_id = ? AND language_id = ?"; 

    $stmt = $mysqli->prepare($updateproduct_sql); 
    $stmt->bind_param('sssiiiss', $image, $ean, $model, $status, $price_sync, $modified_by, $date_modified, $product_id); 

    $stmt2 = $mysqli->prepare($updatedescription_sql); 
    $stmt2->bind_param('sssssisi', $name, $description, $meta_description, $meta_keyword, $tag, $modified_by, $product_id, $language_id); 

    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'] == 4) 
     { 
      $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(); 
    return true; 
} 

function removeslashes($string) 
{ 
    $string=implode("",explode("\\",$string)); 
    return stripslashes(trim($string)); 
} 

私が得るエラーは、任意の提案

Fatal error: Call to a member function bind_param() on boolean in

してくださいますか?私は何が間違っているのか分かりません。あらかじめありがとうございます。

+0

エラーメッセージも貼り付けてください!! – Saty

+0

@Saty私はそんなばかです - 申し訳ありません、私はそれをしませんでした。 致命的なエラー: – Nancy

+0

のメンバー関数bind_param()を呼び出す '$ name = $ row ['name'];'これは 'if($ row ['language_id'] == 4 ) ' – Saty

答えて

2

prepare()メソッドはfalseを返すことができるので、そのことを確認する必要があります。それがなぜfalseを返すのかに関しては、おそらくテーブル名やカラム名(SELECT、UPDATE、WHERE句)が正しくないでしょうか?

また、SQLの解析中に発生したエラーを調べるために、$ query-> error_listのようなものを使用することを検討してください。 (私はときどき実際のSQL文の文字列をエコーし​​てphpMyAdminに貼り付けてテストしますが、間違いなくそこに問題があります)

+0

こんにちは@ジョエルBonetRodríguez、あなたの返信のためのおかしな。問題は、列がテーブルから欠落していたことです。もう一度、あなたの助けのために皆! – Nancy

+0

ようこそ。同じ問題を持つ他の人が簡単に解決策を見つけることができるように、upvoteしてください。乾杯! – JoelBonetR