Dealing with Unisigned 64bit Integers
Posted by: swedishchef (---.bb.sky.com)
Date: July 27, 2021 07:21PM

Hiya to all..

I have a web app that utilises MySQL as the DB back-end. To keep it simple, it has a single table called testbigint and has only 1 field called testval and is set to BigInt(20) - Unsigned and holds the value returned from the MySQL Function uuid_short() - according to the MySQL document it generates a unsigned (see [mariadb.com] for details).

Anyways, with my hosting (IONOS), when I insert the value that is generated from UUID_SHORT() it returned the following value: 10331511505513676677

So using the following lines of code
$bigval = 10331511505513676677;
var_dump($bigval);

Now examining this value via var_dump() it has now converted the number into a float and a loss of precision will follow, for completeness - var_dump() returns 1.0331511505514E+19

According to PHP documentation, PHP is unable to handle unsigned 64bit integers, but how can $bigval be converted into a string

Also, I am using a 64bit version of WampServer

Thanks in advance

Options: ReplyQuote
Re: Dealing with Unisigned 64bit Integers
Posted by: Otomatic (Moderator)
Date: July 28, 2021 04:09PM


Options: ReplyQuote
Re: Dealing with Unisigned 64bit Integers
Posted by: RiggsFolly (Moderator)
Date: July 28, 2021 09:55PM

Simple.

MAX_INT (64bit) is 9223372036854775807 and 10331511505513676677 is greater than that so its converted to something that can hold that number.

echo PHP_INT_MAX . PHP_EOL;
echo '10331511505513676677'.PHP_EOL;

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote


Sorry, only registered users may post in this forum.