I keep receiving an empty array when i try to execute the following code:
$this->DB->prepare('SELECT * FROM Articles WHERE Author = :username AND Timestamp < :timestamp ORDER BY Timestamp DESC LIMIT :limit;');
$this->DB->bind(':username', $username);
$this->DB->bind(':timestamp', $start);
$this->DB->bind(':limit', $numberOfResults, \PDO::PARAM_INT);
$data = $this->DB->execute();
These are the bind
, prepare
and execute
functions:
public function bind($placeholder, $value, $type = \PDO::PARAM_STR) {
$this->preparedQuery->bindParam($placeholder, $value, $type);
}
public function prepare($query) {
if(!$this->preparedQuery = $this->connection->prepare($query)) {
print_r($this->connection->errorInfo());
die();
}
}
public function execute() {
if(!$this->preparedQuery->execute()) {
print_r($this->preparedQuery->errorInfo());
die();
}
return $this->preparedQuery->fetchAll(\PDO::FETCH_ASSOC);
}
I have also tryed to manually execute the query in MySQL Workbench and it's perfectly working.
Edit:
This is what the query looks like:
SELECT * FROM Articles WHERE Author = "TestUser" AND Timestamp < "9000-12-31 23:59:59" ORDER BY Timestamp DESC LIMIT 10;
Edit 2:
I just found out that if I remove the condition about the Timestamp
the query returns values correctly.