i use MYSQLI Extension with prepared statements, what im doing is video encoding, the encoding works, but i have trouble with MYSQL
When the code reaches i get 2 errors ONE is
PHP Fatal error: Call to a member function bind_param() on a non-object in /site.com/processor.php on line 108
HERE the 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();
and when I var_dump($stmt)
it shows bool false. I noticed also, when i encode a other video it works but sometimes it dont works. (always the mysql error) When I comment out this line
exec("$mencoder $temp_upload_dir$post_filename -o $temp_upload_dir$r_post_id.mp4 2>&1", $output);
than MYSQLI works, but i need this line to encode my video. Any Ideas what i doing wrong?
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;
}
Solution: i had this variables in my.cnf
set on
wait_timeout = 30
interactive_timeout = 60
i changed them into
wait_timeout = 3600
interactive_timeout = 3600
and it works, i will google some if i can change these variables in the script, if yes i will do it so, cause i remember the high numbers caused by me RAM problems.
精彩评论