PDO does not return Count

Asked

Viewed 46 times

1

I need to store the result count, but apparently with PDO I can’t store the value. I’ve already select on the outside and the result comes, because I can’t store in the variable $flag the result?

    $query = "SELECT COUNT(*) as flag FROM RESERVAS
              WHERE DATA_RETORNO_REAL = '0000-00-00' AND
                    COD_VEICULO = :veiculo and
                    DATE_FORMAT(DATA_SAIDA, \'%d-%m-%Y\') = :data_reserva
                    ";
    $data = $conexao->prepare($query);    // Prepare query for execution
    $data->execute(array(
    ':veiculo' => $veiculo,
    ':data_reserva' => $data_reserva
    ));
    $saidas = $data->fetch();

    $flag = $saidas['flag'];

On the outside:

inserir a descrição da imagem aqui

  • Do this - var_dump($saidas); - and put the return here.

  • solved taking out DATE_FORMAT(DATA_SAIDA, '%d-%m-%Y') = :data_reserve and replaces by data_output = kurdate(). I do not know why here do not work....

  • Now that you say it, with the \' you were slipping the quotes ('), for this reason did not work, experiment putting DATE_FORMAT(DATA_SAIDA, '%d-%m-%Y').

1 answer

2


Remove the bars from DATE_FORMAT(DATA_SAIDA, \'%d-%m-%Y\'), bars followed by quotation marks (single or double) escape them or the quotation marks were being interpreted as part of the string and not as the delimiter.

Browser other questions tagged

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