Reputation: 342
Within a TYPO3 10 extension I would like to access an external MySQL-database that contains a table with two fileds like "name" and "firstName".
For this I added the external database to my LocalConfiguration.php like explained here: https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Database/Configuration/Index.html
Now I try to access the database in my Controller with the following statement:
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tableName');
$statement = $queryBuilder
->select('name')
->from('tableName')
->execute();
while ($row = $statement->fetch()) {
// Do something with that single row
debug($row);
}
Taken from here: https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Database/QueryBuilder/Index.html
But there is no result in the above statement. When I use the statement with the TYPO3-database the results are as expected:
// use TYPO3\CMS\Core\Utility\GeneralUtility;
// use TYPO3\CMS\Core\Database\ConnectionPool;
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
$statement = $queryBuilder
->select('uid', 'header', 'bodytext')
->from('tt_content')
->execute();
while ($row = $statement->fetch()) {
// Do something with that single row
debug($row);
}
Is there anybody who could give me a hint how to access a database included with doctrine-dbal? Or use something similar like the PDO-statements of PHP in TYPO3.
Upvotes: 0
Views: 658