Why is it important to use proper string delimiters in SQL queries in PHP?

It is important to use proper string delimiters in SQL queries in PHP to prevent SQL injection attacks. Without proper delimiters, user input can be directly inserted into the query, allowing malicious users to manipulate the query and potentially access or modify sensitive data in the database.

// Example of using proper string delimiters in SQL queries
$user_input = $_POST['user_input']; // Assume this is user input from a form

// Using prepared statements with placeholders to prevent SQL injection
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->execute(['username' => $user_input]);
$results = $stmt->fetchAll();