if (module_exists('gd')) { // code to execute if GD library is installed } else { // code to execute if GD library is not installed }
if (module_exists('mysqldnd')) { $pdo = new PDO('mysql:dbname=mydb;host=localhost', 'username', 'password', array( PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8", PDO::MYSQL_ATTR_DIRECT_QUERY => true, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, PDO::MYSQL_ATTR_READ_DEFAULT_FILE => '/etc/mysql/my.cnf', PDO::MYSQL_ATTR_READ_DEFAULT_GROUP => 'client', PDO::MYSQL_ATTR_SSL_KEY => '/path/to/key.pem', PDO::MYSQL_ATTR_SSL_CERT => '/path/to/cert.pem', PDO::MYSQL_ATTR_SSL_CA => '/path/to/ca.pem', PDO::MYSQL_ATTR_COMPRESS => true, )); } else { // code to execute if the module is not installed }In this example, the `module_exists()` function is checking if the `pdo_mysql` package is installed. If it returns `true`, a new `PDO` object is instantiated with various attributes defined, otherwise, the code block within the `else` statement is executed. Package Library: `core` The `module_exists()` function is a built-in PHP function and is part of the `core` package library, which is included in every PHP installation.