What alternative approach can be taken to handle database operations without using prepared statements in PDO?

Using prepared statements in PDO is the recommended approach to handle database operations as it helps prevent SQL injection attacks. However, if you prefer not to use prepared statements, you can manually escape and sanitize user input before constructing SQL queries. This approach requires extra caution to ensure the input is properly sanitized to avoid potential security vulnerabilities.

// Example of handling database operations without using prepared statements in PDO

// Retrieve user input (example only, ensure proper validation and sanitization)
$userInput = $_POST['user_input'];

// Sanitize the user input before using it in the query
$cleanInput = htmlspecialchars($userInput);

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

// Construct the SQL query with the sanitized input
$sql = "SELECT * FROM table WHERE column = '$cleanInput'";

// Execute the query
$stmt = $pdo->query($sql);

// Fetch the results
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

// Handle the results as needed
foreach ($results as $result) {
    // Process each row
}