IP address stored as Integer

I prepare to rewrite one of our applications using Phalcon framework. In the database we store the IP addresses of our devices, and IP allocated to customers as the number (integer). The same applies to the MAC address.

How to write the conversion of the IP address and MAC address to the numbers?

I care about the termination of operating in two directions:

  • insert, update
  • select

I have not found mention in the documentation on the subject. Below I've included links to documentation of how it is possible to do Symfony/Doctrine:

Thank you in advance for help


OK, maybe I will explain how I do it today. In my app I use SQL command like this:

SELECT INETNTOA( ip1 ) AS ip1, INETNTOA( ip2 ) AS ip2 FROM table WHERE id=1

When I update IP address in DB, I use command like this:

UPDATE table SET name=foo, ip=INET_ATON( WHERE id=1

or use ip2long from PHP.

I am convinced that the ORM eloquent it can be written very nicely;)

Or should I try to use Phalcon with the Doctrine?

Try this:

$data = $this->db->fetchOne("SELECT INET_NTOA( ip1 ) AS ip1, INET_NTOA( ip2 ) AS ip2 FROM table WHERE id=1");


Not exactly what I meant. That's why I gave a link to an alternative solution for Symfony. However, if no one will give a better solution it will accept this solution.