use ConnectionManager\ConnectionManager; use ConnectionManager\Extra\MysqlConnection; // Create an instance of ConnectionManager $manager = new ConnectionManager(); // Add a new MySQL connection using a DSN string $manager->setConfig([ 'mysql' => [ 'url' => 'mysql://user:password@hostname:port/database', 'driver' => 'pdo_mysql', 'driver_options' => [ PDO::ATTR_PERSISTENT => true ] ] ]); // Retrieve the MySQL connection $mysql = $manager->getConnection('mysql'); // Execute a query $stmt = $mysql->query('SELECT * FROM mytable'); // Fetch the results $data = $stmt->fetchAll();
use ConnectionManager\ConnectionManager; use ConnectionManager\Extra\PostgresConnection; // Create an instance of ConnectionManager $manager = new ConnectionManager(); // Add a new PostgreSQL connection using a DSN string $manager->setConfig([ 'pgsql' => [ 'url' => 'pgsql://user:password@hostname:port/database', 'driver' => 'pdo_pgsql', 'driver_options' => [ PDO::ATTR_PERSISTENT => true ] ] ]); // Retrieve the PostgreSQL connection $pgsql = $manager->getConnection('pgsql'); // Execute a query $stmt = $pgsql->query('SELECT * FROM mytable'); // Fetch the results $data = $stmt->fetchAll();In these examples, ConnectionManager is used to manage MySQL and PostgreSQL database connections. The `setConfig` method is used to add the respective database connection configurations. The `getConnection` method is called to retrieve the database connection object, which can be used to execute queries. Both examples use the PDO driver and options to configure the connection. The ConnectionManager package library can be downloaded through Composer.