0

I "inherited" from a collegue a MySQL database with dozen of fields. Since I've worked very few times with databases, I'm looking for little advice here.

There's a binary(16) field named "IP": I suppose it is used to store user IPs. A typical stored value is, for example, 00000000000000000000ffff3d024463.

Using PHP (or even MySQL, if this is possibile), how can I convert this data to a plain IP address?

2 Answers2

0

have you tried

$data = hex2bin($ip);
var_dump($data);
//not sure how your data was put into the column IP

on your sql query you can also try

$query = mysql_query("SELECT `HEX(IP)` FROM `database`");
$row = mysql_fetch_array($query);
foreach($row['ip'] as $ip)
{
   $data = hex2bin($ip);
   echo $data."<br />";
}

//code not tested

SQL Query with binary data (PHP and MySQL)

http://php.net/manual/en/function.hex2bin.php

http://php.net/manual/en/function.bin2hex.php

Community
  • 1
  • 1
0

Solved: I had to convert that number using a MySQL function (INET6_NTOA).