Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
Codeigniter Query Builder using MySQL and REGEX with word boundaries adds extra space

With this issue, I would really like to avoid modifying the core files if possible, so a workaround would be extremely helpful.

REGEX works with the 'where' query builder class easy enough, but using the word boundaries breaks it by adding an extra space.

function search($searchQuery){
    $sq = '[[:<:]]'.strtolower($searchQuery).'[[:>:]]';
    $this->db->select('column');
    $this->db->from('table');
    $this->db->where('LOWER(otherColumn) REGEXP', $sq);
    echo $this->db->get_compiled_select();
}

search('billy');

Expected result:

SELECT column FROM table WHERE LOWER(otherColumn) REGEXP '[[:<:]]billy[[:>:]]';

Actual result:

SELECT column FROM table WHERE LOWER(otherColumn) REGEXP [[: < :]]billy[[:>:]]';

This is such a specific issue with a specific stack and I haven't found anybody running into the same issue. I've tried escaping the colons, the <'s, the square brackets, nothing seems to work. Or it adds additional backslashes.

Really any help or direction would be helpful at this point.

Thanks in advance.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

function search($searchQuery){
    $sq = $this->db->escape('[[:<:]]'.strtolower($searchQuery).'[[:>:]]');
    $this->db->select('column');
    $this->db->from('table');
    $this->db->where('LOWER(otherColumn) REGEXP ', $sq, false); 
    echo $this->db->get_compiled_select();
}

search('billy');

For Codeigniter v 3.1.6 and MySQL v5.6


Just because Codeigniter adds space before and after < when compiling the query, I do not know why but it does. And I have escaped the value for variable $sq to mitigate injection Attack or identical. Hence, added third parameter to where function as false to prevent it from re-escaping and adding spaces.

I have not gone through other versions of codeigniter. I hope this will work.

For more information on MySQL REGEXP visit this link: MySQL 5.6 Reference Manual - Regular Expressions

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda