开发者

codeigniter mysql error

Here is my model

public function getDetails($ip)
    {
        $this->db->select('country_code, country_name');
        $this->db->where("'2323' BETWEEN begin_ip_num AND end_ip_num");
        return $this->db->get('ip')->row();
    }

I get this error:

Unknown column ''2323'' in 'where clause'

SELECT `country_code`, `country_name` FROM (`ip`) WHERE `2130706433` BETWEEN begin_ip_num AND end_ip_num

Where开发者_如何学运维 I`m wrong ?


2323 is evaluated as a column name, and begin_ip_num and end_ip_num as values. You must do the opposite, like this :

<?php
public function getDetails($ip)
    {
        $this->db->select('country_code, country_name');
        $this->db->where("begin_ip_num <= 2323 AND end_ip_num >= 2323");
        return $this->db->get('ip')->row();
    }

See MySQL Reference on 'BETWEEN' for how this should be used.


I think you meant:

$this->db->where("$ip BETWEEN begin_ip_num AND end_ip_num");

Because $ip is coming from your model function something you want to check against.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜