Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11601

How to select by a timestamp in MariaDB database without getting an Uncaught mysqli_sql_exception?

$
0
0

I am trying to select the most recently created code from a login code database where that code was created in the last 60 seconds. I am trying to do this with only a MariaDB query, but am getting this error code when I try to run it:

Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')ORDER BY created_atDESC LIMIT 1' at line 4

The query:

 $stmt = $conn->prepare("SELECT *         FROM login_codes         WHERE u_id = ?         AND created_at >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 60 SECOND)         ORDER BY created_at DESC         LIMIT 1");

I have also tried other functions like SUBTIME, but nothing seems to work. The query does work if I remove the entire 'AND created_at' line, but obviously I lose the purpose of the query.


Viewing all articles
Browse latest Browse all 11601

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>