note 79490 added to language.types.integer
| From: | autotelic at NOOOOSPAM dot hotmail dot com | Date: | Thu, 29 Nov 2007 18:36:15 +0000 |
| Subject: | note 79490 added to language.types.integer | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132670@lists.php.net to get a copy of this message | ||
A note about converting IP addresses for storage in database. For MySQL, this is unnecessary as it
has built in support via the INET functions. Also, there is no need to use BIGINT. UNSIGNED INT
is, at 4 bytes, the perfect size for holding an IP (column must be defined as UNSIGNED). This can
basically halve the storage size, as BIGINT is an 8 byte data type.
INET_ATON() converts a dotted IP string to INT:
INSERT table(ip) VALUES(INET_ATON('127.0.0.1'));
INET_NTOA() converts an INT to dotted IP string:
SELECT INET_NTOA(ip) FROM table
returns '127.0.0.1'
Details:
http://dev.mysql.com/doc/refman/5.1/en/miscellaneous-functions.html
----
Server IP: 69.147.83.197
Probable Submitter: 64.183.46.135
----
Manual Page -- http://www.php.net/manual/en/language.types.integer.php
Edit -- https://master.php.net/note/edit/79490
Del: integrated -- https://master.php.net/note/delete/79490/integrated
Del: useless -- https://master.php.net/note/delete/79490/useless
Del: bad code -- https://master.php.net/note/delete/79490/bad+code
Del: spam -- https://master.php.net/note/delete/79490/spam
Del: non-english -- https://master.php.net/note/delete/79490/non-english
Del: in docs -- https://master.php.net/note/delete/79490/in+docs
Del: other reasons-- https://master.php.net/note/delete/79490
Reject -- https://master.php.net/note/reject/79490
Search -- https://master.php.net/manage/user-notes.php