We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon DB queries not working for php function inet_pton

Can someone explain why this query is not not working in phalcon framework ? it works if i run this as direct query on the db , but following

returns null as the value.

    $geo_ip = new GeoIp();

   echo $sql="  SELECT country 
                FROM `geo_ip`
              WHERE addr_type = 'ipv4'
              AND ip_start <= \"".inet_pton($this->ipCheck())."\"
              ORDER  by ip_start DESC
              LIMIT 1 ";

$geo_ip  = new \Phalcon\Mvc\Model\Resultset\Simple(null, $geo_ip , $geo_ip->getReadConnection()->query($sql));
    var_dump($geo_ip->country); 

Output :

SELECT country FROM `geo_ip` WHERE addr_type = 'ipv4' AND ip_start <= "{�<" ORDER by ip_start DESC LIMIT 1 

NULL



11.0k
edited Dec '15
<?php

 $geo_ip = new GeoIp();
$ip_chk  =  inet_pton($this->ipCheck());
 echo $sql="  SELECT country 
              FROM " . $geo_ip ."
             WHERE addr_type = 'ipv4'
             AND ip_start <= '" . $ip_chk ."'
             ORDER  by ip_start DESC
             LIMIT 1 ";

$geo_ip  = new \Phalcon\Mvc\Model\Resultset\Simple(null, $geo_ip , $geo_ip->getReadConnection()->query($sql));
  var_dump($geo_ip->country);

phalcon doesn't allow ` in phql