Which MySQL Datatype use for Store an IP Address?
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.......
We are Recommending you
- Column Sorting using PHP and MySQL
- PHP MySQL - Simple Image Gallery CRUD example from scratch
- Simple Highcharts Chart Example using PHP MySQL Database
- How to get filename from file path in MySQL?
- How to get Ip Address in Codeigniter?
- How to get ip address in jquery?
- How to get ip address using php code?
- How to Execute mysql Query in Laravel?
- How to Get IP Address in Laravel?
- Mysql Hexadecimal Color Code Store in Binary Datatype Example