title: How to convert IPv6 from binary for storage in MySQL
body: <p>I am trying to store IPv6 addresses in MySQL 5.0 in an efficient way. I have read the other questions related to this, <a href="https://stackoverflow.com/questions/420680/how-to-store-ipv6-compatible-address-in-a-relational-database">such as this one</a>. The author of that question eventually chose for two BIGINT fields. My searches have also turned up another often used mechanism: Using a DECIMAL(39,0) to store the IPv6 address. I have two questions about that.</p>
  
  <ol>
  <li>What are the advantages and disadvantages of using DECIMAL(39,0) over the other methods such as 2*BIGINT?</li>
  <li>How do I convert (in PHP) from the binary format as returned by <a href="http://www.php.net/inet_pton" rel="nofollow noreferrer">inet_pton()</a> to a decimal string format usable by MySQL, and how do I convert back so I can pretty-print with inet_ntop()?</li>
  </ol>