I have a code like this:
$consulta= "select campo1, campo2, ..
from tabla
where fecha >'2017-10-12 9:42'
order by fecha asc";
echo $consulta; /*lo tengo para hacer pruebas */
$filas = $db->query($consulta);
if (!$filas) {
$error=$db->errorInfo();
return "Error en la consulta. Error ". $error[2];
} else {
if ($filas->rowcount()==0) echo "<span>No hay resutados</span>";
else
foreach($filas as $fila){
.................
}
Date is of type datetime
.
The issue is that when I run the code on the server it gives me a result (no row) and yet if I copy what is printed in the echo (the query) and execute it directly using the editor in phpMyAdmin I gives the result it should (at this moment 2 rows come out).
When I change the symbol of >
by <
(to see the previous ones to the date) executing the php it removes all the rows to me. If I paste the query, it does it correctly and only removes the events prior to the date.
This same code has been tested with the function now()
of SQL instead of the written date (my idea is to extract it with javascript of the equipment that uses the application) and it works correctly. My problem is that the server time is different and therefore takes out future events hours after they have already passed.
The question is if something similar has happened to someone (a query that works in SQL and not through the query()
method and how it has been solved.