Using PDO with PHP

Asked

Viewed 37 times

0

Good morning, created a function to get the ids of all processes of a table, as shown in the code below

    function getProcessos()
{
   $conecta = new PDO('mysql:host=localhost; dbname=processos','root','root');
    $sql = "SELECT id from processo where opcao='S' limit 10";
    $resultado = $conecta->prepare($sql);
    $resultado->execute();
    $dados = $resultado->fetchAll(PDO::FETCH_OBJ);
       return $dados;
}

Now I need to filter in the table movements by the processes obtained in the function above

$processo = getProcessos();
     // var_dump($processo);

     foreach ($processo as $linhas) {
         $linha = $linhas->id;
         $sql = "select * from andamento where idprocesso=$linha limit 10";
         $stmt = $conecta->prepare($sql);
         var_dump($stmt);
         $stmt->execute();
         $dados = $stmt->fetchAll();
         // var_dump($dados);
}

when I give var_dump in $stmt it returns public 'queryString' => string 'select * from andamento Where idprocesso=5873, where it always modifies the idprocesses according to the getProcesso() function; However when I var_dump($data) it returns 10 empty arrays

  • Why not do it all in method only! in one SQL only!

  • idprocess='$line' tries so

  • Of a var_dump($linha); this will probably tell you a lot about the problem.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.