setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return $pdoconn; } catch (PDOException $e) { // In a real app, you'd log this error and show a generic message die("Database connection failed: " . $e->getMessage()); } } // You can now include this file and call db_connect() to get a database connection.