Laravel Query builder replacing ' into &#039

Viewed 372

I have laravel query builder query where is in the where condition I have an ',

Select * from teams where name ilike ST. HELLEN'S

But when I run this query through Laravel query builder it is converted into

Select * from teams where name ilike ST. HELLEN'S

And at the end I am getting Syntax error. Anyone has any idea how to get through this issue?

I have alreadyt tried these

Select * from teams where name ilike ST. HELLEN\'S
Select * from teams where name ilike `ST. HELLEN'S`

This is the code I have:

$query = "Select * from teams where name ilike ST. HELLEN\'S"; 
$data = DB::select($query); 

Also tried:

DB::select(DB::raw($query));
1 Answers

There are 3 ways to achieve the same

Way1: Use another single quote:'ST. HELLEN''S'

Way2: Use the escape character \ before the single quote': 'ST. HELLEN\'S'

Way3: Use double quotes to enclose string instead of single quotes: "ST. HELLEN'S"

Related