Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use real escape string in Laravel 5.2

is there any built-in way or method available to implement mysqli_real_escape_string method. I have some custom data on which I have to implement this method.

I tried this \DB::escape() method in laravel but got following error.

ErrorException in DatabaseManager.php line 296: call_user_func_array()

expects parameter 1 to be a valid callback, class 'Illuminate\Database\MySqlConnection' does not have a method 'escape'

while If I try manually implement this method mysqli_real_escape_string got following error.

ErrorException in Contact.php line 348: mysqli_real_escape_string() expects exactly 2 parameters, 1 given

I did some R&D, for this method mysqli_real_escape_string() I have to pass 2 parameter 1 is DB connection link, and 2nd is string to implement method action. but now, How I will know Laravel DB connection link?

any idea or solution for this ?

like image 338
Qazi Avatar asked Feb 08 '23 09:02

Qazi


1 Answers

Laravel uses PDO, so there's no escaping, just prepared statements. See the Laravel manual on databases.

If you absolutely need this type of feature, you could try DB::connection()->getPdo()->quote() instead.

like image 83
GrumpyCrouton Avatar answered Feb 10 '23 11:02

GrumpyCrouton