$host = "localhost"; $dbname = "database_name"; $user = "username"; $pass = "password"; try { $pdo = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); }This code connects to a MySQL database using a PDO object. The connection details like host, database, username, and password are passed as parameters to the PDO constructor. The setAttribute method is used to enable error reporting. Package Library: PDO is included in the PHP core. It doesn't require third-party libraries or extensions. However, you may need to install specific database drivers for PDO to work with different databases. For example, for MySQL, you need to have the `pdo_mysql` extension installed and enabled in PHP.