-1

SELECT id FROM videos WHERE dateAdded BETWEEN DATE_ADD(CURDATE(),INTERVAL -1 day) AND CURDATE()

The query above does as expected in phpMyAdmin and returns several results within the date range, but when I run the query within the php script the result is always empty (false).

This query gives results SELECT id FROM videos WHERE 1

The project is rather old running php 5.3 using PDO to run the mysql statements. PDO::errorInfo() indicates that the query went through without errors. It is as if the WHERE part was not interpreted or it was in a different way.

dateAdded is a dateTime parameter that stores the current timestamp of the creation of that particular row.

I already tried to replace the 2 dates with preformatted dates e.g. '2021-06-11 00:00:00' but it did not change anything.

Levi Pike
  • 133
  • 6

1 Answers1

-1

I reworked the script to use mysqli instead of PDO. Now it works properly. It seems like PDO and mysqli treat date related queries different somehow.

Levi Pike
  • 133
  • 6
  • Hate to say the same, but apparently here you had some similar mistake on your part. Of course there is no difference at all between mysqli and pdo. I bet your phpmyadmin and mysqli simply connected to different databases. – Your Common Sense Mar 22 '22 at 12:01
  • @YourCommonSense no. There is only one db to connect to and other queries went through. Hoewever, I could solve it this way. – Levi Pike Apr 14 '22 at 09:13