SQL Connector Service 

Language

en

Version

main

Description

Connector service for any SQL-based database via PDO.

Keywords

sql, database, pdo, data import, fetch data

Copyright

2009-2026

Author

François Suter (Idéative)

Email

typo3@ideative.ch

License

This document is published under the Open Content License available from http://www.opencontent.org/opl.shtml

Rendered

Wed, 22 Apr 2026 11:17:22 +0000

The content of this document is related to TYPO3, a GNU/GPL CMS/Framework available from www.typo3.org.

Introduction 

This extension implements a specific connector service for reading data from any database relying on Doctrine DBAL.

Questions and support 

If you have any questions about this extension, please ask them in the TYPO3 English mailing list, so that others can benefit from the answers. Please use the bug tracker on GitHub to report problem or suggest features (https://github.com/cobwebch/svconnector_sql/issues).

Keeping the developer happy 

Every encouragement keeps the developer ticking, so don't hesitate to send thanks or share your enthusiasm about the extension. If you really want to give something back, you may consider my Amazon wish list: http://www.amazon.co.uk/registry/wishlist/G7DI2AN99Y4F

You may also take a step back and reflect about the beauty of sharing. Think about how much you are benefiting and how much yourself is giving back to the community.

Installation 

Install this extension and you can start using its API for issuing SQL queries to any database inside your own code.

It requires extension “svconnector” which provides the base for all connector services.

Updating to 6.0.0 

Version 6.0.0 adds support for TYPO3 14 and PHP 8.5, while dropping support for TYPO3 12 and PHP 8.1.

Hooks have been entirely removed. Use only events.

Updating to 5.0.0 

Version 5.0.0 adds support for TYPO3 13 and PHP 8.4, while dropping support for TYPO3 11 and PHP 7.4 and 8.0.

Events have been introduced to replace hooks. Existing hooks are still in place, but are deprecated and events should now be used instead (see the svconnector manual for reference).

Updating to 4.0.0 

Version 4.0.0 adds support for TYPO3 12 and PHP 8.1, while dropping support for TYPO3 10. It adapts to the new way of registering Connector Services. The update process should be smooth with "svconnector" version 5.0.0.

Updating to 3.0.0 

Version 3.0.0 adds support for TYPO3 11 and PHP 8.0, while dropping support for TYPO3 8 and 9. Apart from that it does not contain other changes and the update process should be smooth.

Updating to 2.2.0 

The old ADODB-based database abstraction layer was entirely removed in version 2.2.0. This will affect your existing configuration if you used the uri parameter to define your database connections. There is no backward compatibility. Please check the Configuration chapter to check which parameters can be used instead.

A smaller breaking change is that the fetchMode parameter now uses directly a PHP constant (or its equivalent value). Before version 2.2.0, the constant was used as a string and interpreted by the service using constant(). You need to adapt your configuration accordingly.

Configuration 

This chapter describes the parameters that can be used to configure the SQL connector service.

driver 

Type
string
Description

Name of the database system to connect to, taken from the list of available drivers.

See https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#driver

driverClass 

Type
string
Description
Fully-qualified name of a custom driver class.

server 

Type
string
Description
Address of the server to connect to.

user 

Type
string
Description
User name to use to connect to the database.

password 

Type
string
Description
Password to use for the given user.

database 

Type
string
Description
Name of the database to connect to.

query 

Type
string
Description
The actual query to execute.

init 

Type
string
Description

SQL queries to be sent before the actual query (defined in parameter query) is executed. This is typically used to temporarily change the encoding.

Example:

SET NAMES 'utf8mb4';
Copied!

fetchMode 

Type
int
Description

Used to choose the fetch mode, which influences the type of array returned by the recordset (only numerical, associative or first column are supported).

Use the name of the constants from the PDO drivers or the numerical values (numerical = 3, associative = 2, first column = 7)

Reference: https://www.php.net/manual/en/pdostatement.fetch.php

Default
2 (associative)

Special considerations 

Connect to TYPO3's own database 

You can also connect to the database of your current TYPO3 installation. This might be useful to migrate data from one table format to another. You could for example migrate data from tt_news to tx_news_domain_model_news:

EXT:my_extension/Configuration/TCA/Overrides/tx_news_domain_model_news.php
$GLOBALS['TCA']['tx_news_domain_model_news'] = array_replace_recursive($GLOBALS['TCA']['tx_news_domain_model_news'],
[
   'external' => [
      'general' => [
         0 => [
            'connector' => 'sql',
            'parameters' => [
               'driver' => $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['driver'],
               'server' => $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['host'],
               'user' => $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['user'],
               'password' => $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['password'],
               'database' => $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['dbname'],
               'query' => 'SELECT * FROM tt_news LIMIT 5'
            ],
            'data' => 'array',
            'referenceUid' => 'import_id',
            'priority' => 5000,
            'description' => 'News import from own database'
         ]
      ]
   ],
   'columns' => [
      // ...
   ],
]);
Copied!

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 TYPO3CMSCoreUtilityGeneralUtility::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.

Sitemap