Difficulty with PDO

2

I'm starting with the use of PDO and I have a question I could not solve. I do the select below that will return me 2 times:

$sqlSaida = 'SELECT horario 
               FROM HORARIOS
              WHERE COD = :codsaida 
              UNION
             SELECT horario 
               FROM HORARIOS
              WHERE COD = :codretorno;';

$resSaida = $conexao->prepare($sqlSaida);

$resSaida->execute(array(
    ':codsaida' => $codsaida,
    ':codretorno' => $codretorno
));

$saidas = $resSaida->fetchAll();

But I can not store the results, below I can display both, but how could I store them in different variables?

foreach ($saidas as $saida) {
 echo $saida['horario'];
}
    
asked by anonymous 04.12.2015 / 19:02

1 answer

1

Create a array .

    $arrData = []; 
    $x = 0;
    foreach ($saidas as $saida) {
       $arrData[$x]['horario'] = $saida['horario'];
       $arrData[$x]['retorno'] = $saida['retorno'];
       $x++;
    }

    echo "<pre>";
    print_r($arrData['horario']);
    echo "</pre>";
    
04.12.2015 / 19:10