note 80303 added to language.types.integer

From: Date: Wed, 09 Jan 2008 09:06:44 +0000
Subject: note 80303 added to language.types.integer
Groups: php.notes 
Request: Send a blank email to php-notes+get-134961@lists.php.net to get a copy of this message
When handling very large numbers in PHP, you'll notice they get cut off at hexadecimal 7FFFF FFFF. Sometimes, you don't need to use these numbers in an actual calculation in PHP (i.e. just editing and displaying), and just need to save them in a database. In that case, you can let MySQL handle the conversion from and to hexadecimal notation. In the example below, engineers need to save hexadecimal addresses up to FFFF FFFF. To update such a value in MySQL, use the following query, where 'addr' is a column with type unsigned integer(10). <?php $query = " UPDATE hardware_register SET name = ?, type = ?, addr = conv(?, 16, 10) WHERE id = ? "; ?> And selecting: <?php $query = " SELECT name, type, conv(addr, 10, 16) FROM hardware_register WHERE id = ? "; ?> Note that you'll have to treat the resulting addr column as a string everywhere in PHP. You can't do conversions like: <?php $addr_decimal = sprintf("%X", $addr_column); ?> because that'll result in $addr_decimal having the cut-off, maximum int value. ---- Server IP: 213.249.64.162 Probable Submitter: 131.211.40.2 ---- Manual Page -- http://www.php.net/manual/en/language.types.integer.php Edit -- https://master.php.net/note/edit/80303 Del: integrated -- https://master.php.net/note/delete/80303/integrated Del: useless -- https://master.php.net/note/delete/80303/useless Del: bad code -- https://master.php.net/note/delete/80303/bad+code Del: spam -- https://master.php.net/note/delete/80303/spam Del: non-english -- https://master.php.net/note/delete/80303/non-english Del: in docs -- https://master.php.net/note/delete/80303/in+docs Del: other reasons-- https://master.php.net/note/delete/80303 Reject -- https://master.php.net/note/reject/80303 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#134961) next »