I am working on PHP + Slim Framework. I need to migrate MySQL to SQL Server. Something is wrong with the result of returning from a SELECT statement. Here is my example data,
╔════╦═══════╦════════════╦════════════╦═══════════════════════╗
║ id ║item_id║ lat ║ lng ║ timestamp ║
╠════╬═══════╬════════════╬════════════╬═══════════════════════╣
║ 1 ║ 1 ║51.42743450 ║-0.72776696 ║2017-07-05 09:54:49.000║
║ 2 ║ 1 ║51.59665507 ║-0.72777098 ║2017-07-05 11:54:49.000║
║ 3 ║ 2 ║51.59664690 ║-0.67272032 ║2016-08-10 10:11:49.000║
║ 4 ║ 2 ║51.59664874 ║-0.67270288 ║2016-08-10 11:05:49.000║
║ 5 ║ 2 ║51.59665167 ║-0.67271587 ║2016-08-10 10:08:49.000║
╚════╩═══════╩════════════╩════════════╩═══════════════════════╝
And here is the code,
public function test(Request $request, Response $response, $args)
{
$query = 'SELECT item_id, lat, lng FROM mySchema.record WHERE item_id = 1';
$sth = $this->db->prepare($query);
$sth->execute();
$rows = $sth->fetchAll();
$data = array('data' => $rows);
return $response->withJson($data);
}
Previously, in MySQL, data was returned correctly, like this (example),
"data" : [
{
"item_id" : "1",
"lat" : "51.42743450",
"lng" : "-0.72776696"
}
]
But after working with SQL Server, it returns me data like this (example),
"data" : [
{
"item_id" : "1",
"lat" : "51.42743450",
"lng" : "-.72776696"
}
]
You can see that the leading number 0 is cut out from lng . I really don't know how to fix this. Can anyone help? Many thanks.
** EDIT: The Lng data type is DECIMAL (11.8) in SQL Server, which is similar to MySQL
Update
- 0 sprintf(). , . , , .