Does the new MySQLi class automatically handle data sanitization like htmlspecialchars for $_POST['id'] in PHP?

When using the MySQLi class in PHP, it does not automatically handle data sanitization like htmlspecialchars for user input. It is important to manually sanitize user input to prevent SQL injection attacks. This can be done using prepared statements or by using functions like mysqli_real_escape_string.

// Example of sanitizing user input using prepared statements with MySQLi

// Assuming $mysqli is your MySQLi connection object

$id = $_POST['id'];
$id = mysqli_real_escape_string($mysqli, $id);

$stmt = $mysqli->prepare("SELECT * FROM table WHERE id = ?");
$stmt->bind_param("s", $id);
$stmt->execute();
$result = $stmt->get_result();

// Process the result