查询substr Codeigniter的位置

时间:2018-03-23 05:18:41

标签: postgresql codeigniter where

我必须检查数据库中字符串的两个字符。 这是我的代码,但它不起作用。

    function getby_substr() {
    $query =  $this->db
                   ->where('substr(ipv6, 4,2 )', 'c1')
                   ->get('computer_information');
    if ($query->num_rows() > 0) {
        return $query->result();
    }
    return array();
}

谢谢,

1 个答案:

答案 0 :(得分:1)

希望这会对您有所帮助:

使用where子句

      /*replace column_name with your table field name*/
      $query =  $this->db
               ->where('column_name', SUBSTRING(ipv6, 2, 5))
               ->get('computer_information');

使用like子句

     $query =  $this->db
               ->like('column_name', SUBSTRING(ipv6, 2, 5))
               ->get('computer_information');

了解更多:https://www.codeigniter.com/user_guide/database/query_builder.html#selecting-data