Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysqli_real_escape_string() expects exactly 2 parameters, 1 given

Tags:

php

mysqli

if (phpversion() >= '4.3.0'){
    $string = mysqli_real_escape_string($string);
}else{
    $string = mysqli_escape_string($string);
}

All the documentation for mysqli_real_escape_string seems to indicate this is a valid bit of code, but I don't understand why I get this error:

mysqli_real_escape_string() expects exactly 2 parameters, 1 given

like image 227
user880789 Avatar asked Oct 12 '11 16:10

user880789


People also ask

What is the use of Mysqli_real_escape_string () function?

The mysqli_real_escape_string() function is an inbuilt function in PHP which is used to escape all special characters for use in an SQL query. It is used before inserting a string in a database, as it removes any special characters that may interfere with the query operations.

When should I use Mysqli_real_escape_string?

You should use real_escape_string on any parameter you're mixing as a string literal into the sql statement. And only on those string literal values.

Is Mysql_real_escape_string deprecated?

This extension was deprecated in PHP 5.5. 0, and it was removed in PHP 7.0.


2 Answers

Documentation says it needs two parameters:

string mysqli_real_escape_string ( mysqli $link , string $escapestr )

The first one is a link for a mysqli instance, the second one is the string to escape.

like image 149
meze Avatar answered Oct 23 '22 15:10

meze


Following is the proper format to use it :

string mysqli_real_escape_string ( mysqli $link , string $escapestr )

first parameter is mysql connection link identifier, and second is string For more details, you can visit this link : http://in2.php.net/manual/en/mysqli.real-escape-string.php.

like image 26
Nishu Tayal Avatar answered Oct 23 '22 14:10

Nishu Tayal