Which MySQL datatype use for store an IP address?By Hardik Savani | January 7, 2016 | | 941 Viewer | Category : PHP MySql
Share this post:
If you want to store IP address in mysql database then don’t mistake to use varchar datatype because you can use INT UNSIGNED 4(BYTE) datatype. using integer datatype you can save more space in database.
when you fire insert query at that time use INET_ATON() and select query at that time INET_NTOA() use. how to use this function given bellow example.
Create Table :
CREATE TABLE IF NOT EXISTS `ip_addresses` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`ip_address` INT(4) UNSIGNED NOT NULL,
PRIMARY KEY (`id`)
Insert Data :
INSERT INTO `ip_addresses` (`ip_address`) VALUES (INET_ATON("127.0.0.1"));
Select Data :
SELECT id, INET_NTOA(`ip_address`) as ip FROM `ip_addresses`;
Try this, this is a very simple.......
- Jquery notification popup box example using toastr JS plugin with demo
- How to use where clause with mysql function in Laravel 5?
- How to generate route with query string parameter in Laravel 5?
- Mediafire PHP file uploading and get link example
- Jquery - Animated typing effect using typed js example with demo
- How to add LIKE query in Elasticsearch?
- PHP - How to remove duplicate values from multidimensional array?
- How to check current password using hash check in Laravel 5.3?