I use this to create a unique code for each product in my store,
echo base_convert(uniqid(),16,10);
For instance,
1403802682572650
My query is simple like this,
$sql = "
SELECT *
FROM page AS p
LEFT JOIN stock AS o
ON o.id = p.page_id
WHERE p.type = ?
AND p.hide != ?
ORDER BY p.backdated_on
";
And when I want to get the product code, I do this,
var_dump($product->code);
But PHP returns float(1.4038026825726E+15)
instead of 1403802682572650
Why does PHP returns float
instead of string
? How can I get the number as it is?
Or should I convert/cast the number to string or varchar in my SQL query before requesting result from the db table?
EDIT: Found the bug in my code.
I have a line to convert json to array and that convert the string into float, for instance,
echo json_decode("1403802682572650", true); // 1.4038026825726E+15