I’m saving ip addresses as strings using php’s inet_pton as a four byte string. To create a human readable representation using mysql I want to use inet_ntoaMySQL, however, it appears to only accept integer values.
So, how do I read a string like !"# (corresponding to ip 32.33.34.35, also notice the space) as an integer (corresponding to 539042339 in this example)?
You can use something
Hex()to convert the string to hexadecimal, thenConv()to convert it to base 10.SELECT inet_ntoa(conv(hex(' !"#'), 16, 10))