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

在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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样