dongyongju9560
2015-01-27 03:19
浏览 82
已采纳

在PostgreSQL上错误ILIKE

I've a project that use PostgreSQL and new with it. Below is the error that i was facing. I also has searched on google but cannot find the solution.

Fatal error: Call to undefined method CI_DB_postgre_driver::ilike() in D:\htdocs\poes\system\applicationapyd\classes\datafilter.php on line 162

I'm using codeigniter framework. This code is from datafilter.php $this->db->ilike($name, $value); On my controller,

$query1 = "SELECT DISTINCT users.* FROM users LEFT JOIN login ON users.user_id=login.login_user_id;";
$filter->db->query($query1);
$filter->name = new inputField("Name :", "user_name");
$filter->name->clause = "ilike";
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dtvpl739577 2015-01-29 03:25
    已采纳

    I just solve the issue, need to add this function in system/database/DB_active_rec.php to use ilike

    function ilike($field, $match = '', $side = 'both')
    {
        return $this->_ilike($field, $match, 'AND ', $side);
    }
    
    function _ilike($field, $match = '', $type = 'AND ', $side = 'both', $not = '')
    {
    if ( ! is_array($field))
    {
    $field = array($field => $match);
    }
    
      foreach ($field as $k => $v)
      {
    $k = $this->_protect_identifiers($k);
    
    $prefix = (count($this->ar_like) == 0) ? '' : $type;
    
    $v = $this->escape_like_str($v);
    
    if ($side == 'before')
    {
    $like_statement = $prefix." $k $not ILIKE '%{$v}'";
      }
      elseif ($side == ‘after’)
      {
    $like_statement = $prefix." $k $not ILIKE '{$v}%'";
      }
      else
      {
    $like_statement = $prefix." $k $not ILIKE '%{$v}%'";
      }
    
      // some platforms require an escape sequence definition for ILIKE wildcards
      if ($this->_like_escape_str != ‘’)
      {
    $like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_chr);
    }
    
      $this->ar_like[] = $like_statement;
      if ($this->ar_caching === TRUE)
      {
    $this->ar_cache_ilike[] = $like_statement;
    $this->ar_cache_exists[] = 'ilike';
    }
    
      }
      return $this;
    }
    

    source from https://ellislab.com/forums/viewthread/87725/#808269

    已采纳该答案
    打赏 评论
  • dp610807 2019-02-24 14:13

    like this

    $param = "%".urldecode($this->uri->segment(4))."%";
                if(!empty($this->uri->segment(4))){
                    $this->db->where("name ilike",$param); 
                 }
    
    打赏 评论

相关推荐 更多相似问题