Developer's manual

Getting data from another database using the SQL connector service is a really easy task. The first step is to get the proper service object, with the desired parameters:

$parameters = [
   'driver' => 'postgres',
   'driverClass' => 'Vendor\DBAL\Driver\PDODblib\Driver',
   'server' => '127.0.0.1',
   'user' => 'some_user',
   'password' => 'some_password',
   'database' => 'some_db',
   'query' => 'SELECT * FROM foo ORDER BY bar'
];
$registry = GeneralUtility::makeInstance(\Cobweb\Svconnector\Registry\ConnectorRegistry::class);
$connector = $registry->getServiceForType('sql', $parameters);
Copied!

The next step is simply to call the appropriate method from the API depending on which format you want to have in return. For a PHP array:

$data = $connector->fetchArray();
Copied!

Obviously this is not limited to issuing SELECT queries, although it is what it was designed for, since connector services are really about getting data from some source. Other types of queries have not been tested.

The fetchRaw() method returns the same array as fetchArray(). The fetchXML() method returns the array created by fetchArray() transformed to XML using \TYPO3\CMS\Core\Utility\GeneralUtility::array2xml.

Note that the connection is neither permanent, nor stored in the connector object (as one could imagine the object being called several times but for different connections), so it may not be ideal to use if you need to perform many queries on the same database in a given code execution run.