Which MySQL datatype use for store an IP address?By Hardik Savani | January 7, 2016 | | 4065 Viewer | Category : PHP MySql
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.......
- Solved Issue - "/usr/bin/env: ‘node’: No such file or directory"
- How to get last inserted id in laravel 5?
- How to get file size from URL in Laravel 5?
- Laravel ajax render view with data example
- Laravel 5 - How to implement gravatar image using thomaswelton/laravel-gravatar package
- PHP Image upload without refreshing page using jquery example
- Laravel 5.5 Simple CMS Website example using asgardcms
- Laravel 5 - How to convert file(image, audio, video) extension using CloudConvert?