What error in this while PHP?

-2

The code below selects all results whose thumbnail of the video has not yet been created and if it was not, it creates a new one, but I'm getting an error that I can not find the solution:

    $video = BD::conn()->prepare("SELECT * FROM episodios WHERE thumb = '0' OR thumb = ''");
    $video->execute();
    $c = $video->rowCount();
    if($c >= 1){
        while($dados = $video->fetch()){
            $id = $dados["id"];
            $serie = $dados["id_serie"];
            $temporada = $dados["temporada"];
            $episodio = $dados["episodio"];

            if (!is_dir("D:/thumbs/".$serie)) {
                mkdir("D:/thumbs/".$serie, 0777);
            }
            if (!is_dir("D:/thumbs/".$serie."/".$temporada)) {
                mkdir("D:/thumbs/".$serie."/".$temporada, 0777);
            }

            /*o erro está sendo gerado aqui*/   
            if(is_dir("D:/videos/".$anime."/original/")) {
                $video = "D:/videos/".$serie."/original/".$temporada."/".$episodio.".mp4";
            }else{
                $video = "D:/videos/".$anime."/dublado/".$temporada."/".$episodio.".mp4";
            }
            /*fim da parte com erro*/
        }
  }

When I comment on the block that is supposed to be generating the error, the while runs normally, but when I add the same I get this error:

  

Fatal error: Call to a member function fetch () on string in

    
asked by anonymous 06.02.2017 / 15:51

1 answer

4

It turns out that you are calling the function FETCH on the object $video but at the end of the code you are about writing the variable that had an OBJECT with a STRING , there the error.

Change the ending to:

if(is_dir("D:/videos/".$anime."/original/")) {
            $video1 = "D:/videos/".$serie."/original/".$temporada."/".$episodio.".mp4";
        }else{
            $video1 = "D:/videos/".$anime."/dublado/".$temporada."/".$episodio.".mp4";
        }

Remember that $ video1 will only have the last value of the Loop, if you want to store all the values you must use an Array, for example $videos[$id]

    
06.02.2017 / 15:59