In what situations should PDO::quote be used instead of manually escaping values for SQL insert statements in PHP?

When dealing with SQL insert statements in PHP, it is recommended to use PDO::quote to properly escape values to prevent SQL injection attacks. PDO::quote not only escapes special characters but also properly handles data types, making it a safer and more reliable option compared to manually escaping values.

// Connect to the database using PDO
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');

// User input to be inserted into the database
$userInput = "John Doe";

// Use PDO::quote to properly escape the user input
$escapedInput = $pdo->quote($userInput);

// Insert the escaped input into the database
$pdo->query("INSERT INTO users (name) VALUES ($escapedInput)");