How can a PDO connection be established in Symfony2 without using Doctrine?

To establish a PDO connection in Symfony2 without using Doctrine, you can directly create a PDO object and pass the database credentials to it. This allows you to interact with the database using raw SQL queries without the need for an ORM like Doctrine.

// Database credentials
$host = 'localhost';
$dbname = 'my_database';
$username = 'root';
$password = '';

// Create PDO connection
try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully";
} catch (PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}