Reputation: 16181
I exported data from one of my tables and I'm trying to make a Laravel migration out of. In order to make it work I'm using DB::statement()
like this:
DB::statement("INSERT INTO `course` (`id`, `name`)
VALUES (1, 'PHP programming "PHP for dummies"')");
How can I escape the double quotes in the course.name column, within DB::statement()
quotes?
I tried escaping them with backslash - did not work.
Upvotes: 0
Views: 408
Reputation: 1916
You can use addslashes('Some string with "quotes"')
.
Or also the ol' mysqli_real_escape_string()
A better way to do it is:
DB::statement("INSERT INTO `course` (`id`, `name`)
VALUES (?, ?)", [1, 'PHP programming "PHP for dummies"']);
Laravel will then take care of the rest.
Upvotes: 1