How to use a real escape line in Laravel 5.2

is there a built-in method or method for implementing the method mysqli_real_escape_string. I have some user data on which I have to implement this method.

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

Error Exception in DatabaseManager.php 296 line: call_user_func_array ()

expects parameter 1 to be a valid callback; class "Illuminate \ Database \ MySqlConnection" does not have an escape method

while If I try to manually implement this method, I mysqli_real_escape_stringreceived the following error.

Error 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 need to pass 2 parameters 1, this is a connection to a DB connection, and 2nd is a string to implement the action of the method. but now, How do I find out the link to the Laravel DB connection?

any idea or solution for this?

+4
source share
1 answer

Laravel uses PDO , so there are no escaped, only prepared statements. See the Laravel Guide to Databases .

If you absolutely need this feature, you can try it DB::connection()->getPdo()->quote().

+5
source

All Articles