It try to only get the last 30 records in my application. Using PDO other queries work perfectly fine, but trying the following query I get an error.
I try to insert an integer $amount with the value of 30 into the database. But it is received as an String, which gives an SQL syntax error.
$amount = 30;
$query = "SELECT Dyn.RecordTime, Driver.bikeID, Driver.firstname, Driver.middlename, Driver.lastname, Dyn.comboDb, Driver.DriverID ,TP.idTransponder
FROM passage
INNER JOIN dynamic_measurement Dyn on passage.idPassage = Dyn.passage_idPassage
INNER JOIN driver_transponder dt on passage.transponder_idTransponder = dt.transponder_idTransponder
INNER JOIN transponder TP on dt.transponder_idTransponder = TP.idTransponder
INNER JOIN driver Driver on dt.driver_DriverID = Driver.DriverID
ORDER BY Dyn.RecordTime DESC
LIMIT ?";
return $this->query($query, array(strval($amount)));
The error:
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to use near ''30'' at line 8
This is the function called from the above code, it is in a class that extends the PDO database connection, this is called by $this->connect
protected function query($query, $params = array()) : array
{
$stmt = $this->connect()->prepare($query);
$stmt->execute($params);
$data = $stmt->fetchAll();
return $data;
}
Does anyone know how I can fix this?