My DB has three columns, which are id, seconds (a timestamp) and values (a float). When I send "SELECT * FROM lin_m4 ORDER BY id DESC LIMIT 1", where lin_m4 is the name of the table, the milliseconds returned value of the seconds column are removed.
Here is a tipical row of my DB (note that the names are written in Spanish):
( id, segundos, valor) -> '145788', '2021-06-17 15:43:15.825', '-0.15469'
And here is what I get after a request (in JSON format):
[{"id":145788,"segundos":"2021-06-17 15:43:15","valor":-0.15469}]
.
My code in PHP is:
<?php
header("Content-Type: application/json; charset=UTF-8");
$servername="localhost";
$username="root";
$password="something";
$dbname="somethingelse";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . $conn->connect_error);
}
$sql='SELECT * FROM lin_m4 ORDER BY id DESC LIMIT 1;';
$stmt = $conn->prepare($sql);
$stmt->execute();
$result = $stmt->get_result();
$outp = $result->fetch_all(MYSQLI_ASSOC);
$outpf = json_encode($outp);
echo $outpf;
$conn->close();
?>
I want to know how to prevent the milliseconds from being dropped when I make a request.