I just Want to Get Newest Record From a Database Table and i got this error when i used LIMIT how can i solve this?
Connection established.
Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 102 [code] => 102 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'LIMIT'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'LIMIT'. ) )
$query = 'SELECT EventTime, EventHumidity, EventTemperature FROM TxnFMISHumidityTempEvent ORDER BY EventID DESC LIMIT 1';
$stmt = sqlsrv_query( $conn, $query );
if( $stmt === false)
{
die( print_r( sqlsrv_errors(), true) );
}
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) )
{
$css_class=' class="row"';
echo "<tr '.$css_class.'>";
echo "<td>SNSRP001</td>";
echo "<td>MIS</td>";
echo "<td>" .$Date = $row['EventTime']->format('Y-m-d H:i:s'). "</td>";
echo "<td>" .$row['EventHumidity']. "</td>";
echo "<td>" .$row['EventTemperature']. "</td>";
echo "</tr>";
}
sqlsrv_free_stmt( $stmt);