How can PHP developers implement Typehinting, Escaping, or Prepared Statements to safeguard against SQL Injections?

SQL Injections can be prevented by implementing Typehinting, Escaping, or Prepared Statements in PHP code. Typehinting ensures that only expected data types are accepted as input, Escaping helps to sanitize user input by escaping special characters, and Prepared Statements separate SQL code from user input, preventing malicious code execution.

// Typehinting example
function getUserById(int $userId) {
    // Function logic
}

// Escaping example
$userInput = "John O'Connor";
$escapedInput = mysqli_real_escape_string($connection, $userInput);

// Prepared Statements example
$stmt = $connection->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $username);
$username = "admin";
$stmt->execute();