onlinecode

Which MySQL datatype use for store an IP address?

Which MySQL datatype use for store an IP address?

In this post we will give you information about Which MySQL datatype use for store an IP address?. Hear we will give you detail about Which MySQL datatype use for store an IP address?And how to use it also give you demo for it if it is necessary.

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 :

Also see:How to get Ip Address in Codeigniter?

SELECT id, INET_NTOA('ip_address') as ip FROM 'ip_addresses';

Try this, this is a very simple…….

Hope this code and post will helped you for implement Which MySQL datatype use for store an IP address?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Exit mobile version