I have a query in my PHP code that was working normal, but it suddenly stopped working without me making any kind of change.
SELECT * FROM comportamento_loja
where ativado = 1
and datahoje BETWEEN DATE_FORMAT(STR_TO_DATE(data_inicial, '%Y-%m-%d'), '%d/%m/%Y') AND DATE_FORMAT(STR_TO_DATE(data_final, '%Y-%m-%d'), '%d/%m/%Y')
I tested it directly on phpadmin that was working before and also does not work anymore. I ran a test with this other query directly in phpadmin:
SELECT * FROM comportamento_loja
where ativado = 1
and 2018-07-05 BETWEEN (data_inicial) AND (data_final)
And it does not work, but if I put quotation marks on the date it works:
SELECT * FROM comportamento_loja
where ativado = 1
and '2018-07-05' BETWEEN (data_inicial) AND (data_final)
So I tried to use this query that works in PHP but it also does not work, maybe because the parameter is without quotes, I do not know. I've been doing this for two days and nothing, I've tried in many ways and nothing, can anyone get a solution to this problem?
I am using: Win7, wamp server, PHP version 7, 5.7.14 - MySQL and also PDO, but as I said all queries I also testo in phpadmin and nothing.
This is my code:
$data_atual = date("d/m/Y");
$sql = "SELECT * FROM comportamento_loja where ativado = 1 and ? BETWEEN DATE_FORMAT(STR_TO_DATE(data_inicial, '%Y-%m-%d'), '%d/%m/%Y') AND DATE_FORMAT(STR_TO_DATE(data_final, '%Y-%m-%d'), '%d/%m/%Y')
try {
$stmt = $con->prepare($sql);
$stmt->execute($data_atual);
$comportamento = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
catch(PDOException $error) {
echo '<span class="box-error"><h5>Erro ao carregar comportamento_loja:' . '<span class="description-error">' .$error->getMessage(). '</span>' .'</span>';
}
$stmt = null;