Similar to this unsolved question
My PHP output requires JSON_NUMERIC_CHECK
enabled, however there is one string nick column in my database that needs to be returned originally as a string. Values in that column can contain numbers and there's no length restriction. Code example:
$response["players"] = array();
...
$stmt = $connection->prepare('SELECT id, nick FROM players WHERE NOT id = ? ORDER BY nick');
$stmt->bind_param('i', $_POST["id"]);
$stmt->execute();
$result = $stmt->bind_result($id, $nick);
while ($stmt->fetch()) {
$players = array();
$players["id"] = $id;
$players["nick"] = $nick;
array_push($response["players"], $players);
}
...
echo json_encode($response, JSON_NUMERIC_CHECK);
For example, nick "007" is being returned as "7" and I need it to be the original "007". Removing "JSON_NUMERIC_CHECK" helps, but it bugs the rest of the code. Strval() function used like quoted below didn't help.
$result = $stmt->bind_result($id, strval($nick));
$players["nick"] = strval($nick);