Home >Backend Development >PHP Tutorial >Why Does `mysqli_real_escape_string()` Throw an 'expects exactly 2 parameters, 1 given' Error?
Error: "mysqli_real_escape_string() expects exactly 2 parameters, 1 given"
Question:
When attempting to use the mysqli_real_escape_string() function, the following error is encountered:
mysqli_real_escape_string() expects exactly 2 parameters, 1 given
Answer:
According to the function's documentation, it requires two parameters:
The error indicates that the function is being called with only one parameter, which is likely the string to be escaped.
Example:
The following code snippet provides a correct example of how to use the mysqli_real_escape_string() function:
$mysqli = mysqli_connect('localhost', 'username', 'password', 'database'); $escapedString = mysqli_real_escape_string($mysqli, $string);
In this example, $mysqli represents the connection to the MySQL database, and $string is the string to be escaped. The mysqli_real_escape_string() function will correctly apply escaping to the input string and return the escaped version in $escapedString.
The above is the detailed content of Why Does `mysqli_real_escape_string()` Throw an 'expects exactly 2 parameters, 1 given' Error?. For more information, please follow other related articles on the PHP Chinese website!