How can the use of the mysql_real_escape_string function impact the security of the database query?

Using the mysql_real_escape_string function can help prevent SQL injection attacks by escaping special characters in a string before sending it to the database. This function adds a layer of security by ensuring that user input is sanitized and cannot be used to manipulate the query.

// Connect to the database
$db = mysqli_connect("localhost", "username", "password", "database");

// Sanitize user input using mysql_real_escape_string
$user_input = mysqli_real_escape_string($db, $_POST['user_input']);

// Use the sanitized input in the query
$query = "SELECT * FROM users WHERE username = '$user_input'";
$result = mysqli_query($db, $query);

// Process the query result
// ...