Jump to content

How to Convert and Store


Guest saro
 Share

Recommended Posts

Guest saro

I have a string value for (ex) 17.200.58.111.its an IP address. its value is 0 minimum and 255 maximum. (0 to 255).(0 to 255).(0 to 255).(0 to 255).i need this string to store in sql db as integer.i mean i have to concatenate the string value and store it as an integer,(for ex) if i have 12.322.55.101 (string)than i need 1232255101 (integer) as my result.how to solve this

Link to comment
Share on other sites

Why don't you try this way:0. Declare 2 temporary strings to be used in the process: strA & strB1. Store the string in strA 2. Use a string-replacement-function to search for the DOT (.) in strA and replace it with an empty string. You may need to use these two functions: 3.a. To find the position of the first dot use: INSTR(c,char) 3.b. MID(c,start[,end]) now strB=strA (store the result in strB) Every IP Address always contain three dots, therefore repeat this Replacement two more times using For 1 to 3 ... next ... then concatenating and joining sub strings ...)4. Store the Temp string value (Dots cleaned) in your DB Table/whatever your long period storage is.5.

I have a string value for (ex) 17.200.58.111.its an IP address. its value is 0 minimum and 255 maximum. (0 to 255).(0 to 255).(0 to 255).(0 to 255).i need this string to store in sql db as integer.i mean i have to concatenate the string value and store it as an integer,(for ex) if i have 12.322.55.101 (string)than i need 1232255101 (integer) as my result.how to solve this
Link to comment
Share on other sites

I would just use varchar to store IP addresses. Storing IP addresses as integers causes problems. For example, one user's IP is 16.115.224.108 while another user's could be 161.152.24.108. When you convert both IP addresses to an integer, they will become the same value even though they are completely different addresses (16115224108).If you really want to store the IP address as an integer and you're using MySQL as your database, you should use MySQL's inet_aton() function to convert IPv4 addresses to integers and use the inet_ntoa() function to do the vice versa.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...