phpmysqlmysqlimicrotime

PHP MySQLi prepared statements select rows that are added to records in specific time


I'm having a similar error: PHP mysqli condition greater than or less than symbol error

But I don't find a solution to this since my application is a bit different.

I have following statement right now:

$stmt = $this->mysqli->prepare("SELECT * FROM applications");
$stmt->bind_param("i", $MTNOW);

Everytime my users sends a new application there will be a field named "mtime" which stands "microtime" and it's rounded to numeric format without a double value so it's 1489344810.

How do I can make a calculation to prepared statement like that it will select each row's microtime and increase it by 18000 seconds (5 hours) so I can compare the result to current microtime? It should show only results that are created in 5 hours. Rest of the records will not be shown.

The idea:

SELECT * FROM applications WHERE (mtime+18000) < ?
bind_param("i", $MTNOW);

Solution

  • Check the documentation:

    http://php.net/manual/en/pdostatement.bindparam.php

    $stmt = $this->mysqli->prepare("SELECT * FROM applications WHERE mtime < ?");
    $stmt->bind_param("1", (yourValue + or - 18000));
    $stmt->execute();
    return $stmt->fetchAll(PDO::FETCH_OBJ);