2011-08-02 110 views
2

我使用mysqli擴展和預處理語句,什麼IM做的是視頻編碼,編碼工作,但我有麻煩MYSQLmysqli的預處理語句問題

當代碼達到我得到2個錯誤ONE是

PHP Fatal error: Call to a member function bind_param() on a non-object in /site.com/processor.php on line 108 

這裏的SQL

$sql = "UPDATE videos_to_edit SET status = 'finished' WHERE post_id = ?"; 
    $stmt = $mysqli->prepare($sql); 
    $stmt->bind_param('i', $id); 
    $stmt->execute(); 
    $stmt->close(); 

,當我var_dump($stmt)它顯示布爾假。我注意到,當我編碼其他視頻時,它的工作,但有時它不工作。 (總是MySQL錯誤)當我註釋掉該行

exec("$mencoder $temp_upload_dir$post_filename -o $temp_upload_dir$r_post_id.mp4 2>&1", $output); 

比mysqli的作品,但我需要這行編碼我的視頻。任何想法我做錯了什麼?

set_time_limit(0); 


if(!file_exists($pcp ."processor1")) { 

    $sql = "SELECT post_id, filename, status FROM videos_to_edit WHERE status = 'pending' ORDER BY post_id ASC LIMIT 1"; 
    $stmt = $mysqli->prepare($sql); 
    $stmt->execute(); 
    $stmt->bind_result($r_post_id, $post_filename, $status); 
    $stmt->store_result(); 
    $checker = $stmt->num_rows; 
    $stmt->fetch(); 
    $stmt->close(); 
    $id = $r_post_id; 
    //$video = null; 

    if($checker >= 1 && $status != "encoding" && $status != "finished" && $status != "removed") { 


     $sql = "UPDATE videos_to_edit SET status = 'encoding' WHERE post_id = ?"; 
     $stmt = $mysqli->prepare($sql); 
     $stmt->bind_param('i', $r_post_id); 
     $stmt->execute(); 
     $stmt->close(); 

     $ourFileName = $pcp ."processor1"; 
     $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); 
     fclose($ourFileHandle); 


     exec("$mencoder $temp_upload_dir$post_filename -o $temp_upload_dir$r_post_id.mp4 2>&1", $output); 


     foreach($output as $error) { 
      if(preg_match('/============ Sorry, this file format is not recognized\/supported =============/', $error)) { 
       $error1 = "error"; 
       break; 
      } 
     } 


     if(!isset($error1)) { 

      exec("$mp4box $temp_upload_dir$r_post_id.mp4"); 

      exec("$mplayer $temp_upload_dir$r_post_id.mp4 2>&1", $video); 

      foreach($video as $vidlenght) { 
       if(preg_match('/ID_LENGTH=/', $vidlenght)) { 
        $duration = $vidlenght; 
        $duration = explode("=",$duration); 
        $duration = round($duration['1']); 
        break; 
       } 
      } 

      $hms = sec2hms($duration); 

      mkdir("$temp_upload_dir$r_post_id", 0700); 

      $duration1 = round($duration/15); 

      for($b = 1; $b <= 15; $b++) { 

      $time = $b * $duration1; 

      exec("$ffmpeg -ss $time -i $temp_upload_dir$r_post_id.mp4 -r 1 -vframes 15 -y -s 190x143 -f image2 $temp_upload_dir/$r_post_id/$r_post_id-$b.jpg 2>&1", $mplayer); 

      } 

      $sql = "UPDATE videos_to_edit SET status = 'finished' WHERE post_id = ?"; 
      $stmt = $mysqli->prepare($sql); 
      $stmt->bind_param('i', $id); 
      $stmt->execute(); 
      $stmt->close(); 

      $sql = "INSERT INTO post_lenght (post_id, post_length, seconds) VALUES (?, ?, ?)"; 
      $stmt = $mysqli->prepare($sql); 
      $stmt->bind_param('iss', $r_post_id, $hms, $duration); 
      $stmt->execute(); 
      $stmt->close(); 

      $thumbdir1 = $temp_upload_dir . $r_post_id; 
      $thumbdest = $thumbdir.$r_post_id; 

      $videotempdir = $temp_upload_dir . $r_post_id . ".mp4"; 
      $videodes = $videodir . $r_post_id . ".mp4"; 

      $videotempdirsrc = $temp_upload_dir . $post_filename; 
      $videodessrc = $temp_upload_dir . "src/" . $post_filename; 

      full_copy($thumbdir1, $thumbdest); 
      rename($videotempdir, $videodes); 
      rename($videotempdirsrc, $videodessrc); 

      recursiveDelete($thumbdir1); 



      unlink($pcp ."processor1"); 

      unset($video); 
      unset($hms); 
      unset($vidlenght); 
      unset($duration); 

     } else { 

      $sql = "UPDATE videos_to_edit SET status = 'error' WHERE post_id = ?"; 
      $stmt = $mysqli->prepare($sql); 
      $stmt->bind_param('i', $r_post_id); 
      $stmt->execute(); 
      $stmt->close(); 

      unlink($pcp ."processor1"); 
     } 
    } 
    exit; 
} 

解決辦法:我曾在my.cnf集這個變量上

wait_timeout = 30 
interactive_timeout = 60 

我改變了他們進入

wait_timeout = 3600 
interactive_timeout = 3600 

和它的作品,我將谷歌一些,如果我可以改變這些變量腳本,如果是的話,我會這樣做,因爲我記得由於RAM問題導致的高數字。

+0

您可以使用is_readable而不是打開和關閉 –

+0

檢查prepare call的返回值以查看它是否成功。 http://php.net/manual/en/mysqli.prepare.php看到http://php.net/manual/en/mysqli.error.php太 –

+0

那怎麼幫助我的問題嗎?對不起,我不明白它 – HeroMan

回答

2

作爲開始,這樣做

$sql = "UPDATE videos_to_edit SET status = 'finished' WHERE post_id = ?"; 
$stmt = $mysqli->prepare($sql); 
if(!$stmt = $mysqli->prepare($sql)) { 
    echo $mysqli->error; 
} 


$stmt->bind_param('i', $id); 
$stmt->execute(); 
$stmt->close(); 

只是爲了看看mysqli的不得不說的問題:)

UDPATE

根據您在下面評論,事實上,你在做視頻編碼(這可能需要很多時間)和事實的mysqli連接的默認超時是30秒(如果沒記錯的話)。

我認爲它很可能是你的連接超時:)嘗試使用此方法超時提高到一個小時。

$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 3600); 
+1

我收到此錯誤信息:MySQL服務器已消失 – HeroMan

+0

我將添加一個更新的答案 – JustDanyul

+0

我加入你的代碼頂在我的代碼,但我仍然得到同樣的MySQL錯誤,服務器消失 – HeroMan