Using REGEXP with Laravel query builder

…衆ロ難τιáo~ 提交于 2019-12-13 03:54:41

问题


I have the following query:

$registros = Oportunidade::whereRaw("descricao REGEXP '[[:<:]]". $search ."[[:>:]]'")->get();   

SQLSTATE[HY000]: General error: 1 no such function: REGEXP (SQL: select * from "oportunidades" where descricao REGEXP '[[:<:]]java[[:>:]]')

Also tried:

$registros = Oportunidade::where("descricao", "REGEXP", "'[[:<:]]'" .$search . "'[[:>:]]'")->get();

But for some reason I'm receiving this:

SQLSTATE[HY000]: General error: 1 no such function: REGEXP (SQL: select * from "oportunidades" where "descricao" REGEXP '[[:<:]]'java'[[:>:]]')

SQLSTATE[HY000]: General error: 1 no such function: REGEXP

Why am I getting this error and how could I fix it ? The query works perfect without laravel.

Why Doing this ?

I was using like %value%:

SELECT * FROM mytable where description like %STRING%

The problem is: When I search for JAVA it returns me even the records with JAVAscript. But, JAVA != JavaScript, right ? How can I work around it using Laravel?
The only way I found using pure Mysql was with REGEXP

来源:https://stackoverflow.com/questions/47320448/using-regexp-with-laravel-query-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!