Mysqli准备的语句问题

问题描述 投票:2回答:1

我使用带有准备好的语句的MYSQLI扩展,即时通讯正在做的是视频编码,编码有效,但是我在使用MYSQL时遇到问题

当代码到达时我遇到2个错误,其中一个是

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)时,它显示bool为假。我还注意到,当我编码其他视频时,它可以工作,但有时不起作用。 (总是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

并且有效,如果可以更改脚本中的这些变量,我会用谷歌搜索,如果可以,我会这样做,因为我记得由内存问题引起的高数值。

php mysql mysqli prepared-statement
1个回答
1
投票
首先,这样做
© www.soinside.com 2019 - 2024. All rights reserved.