setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $pdo->prepare("INSERT INTO users (name, email) VALUES (:name, :email)"); $stmt->bindParam(':name', $name); $stmt->bindParam(':email', $email); $name = "John Doe"; $email = "john@example.com"; $stmt->execute(); echo "New record created successfully"; } catch (PDOException $e) { $errno = $e->getCode(); $error = $e->getMessage(); echo "Error $errno: $error"; } ?>In this example, we use PDO (PHP Data Objects) to connect to a database and insert a new record. If an error occurs, we catch the PDOException, retrieve the error number and error message using getCode() and getMessage() methods, and display them. Package/library: PDO (PHP Data Objects)