TYPO3 Doctrine DBAL convenience store

In my former post [1] I focused mainly on the issue to migrate existing DB calls from TYPO3-DB to Doctrine DBAL. This one is about writing tiny vanilla DB statements without any „special“ clauses. Only for these „Gimme everything from one table“ or „Just delete that one row“ situations.

Getting the connection

First you have to get your connection like you did it in the good ol‘ days by declaring $databaseConnection = $GLOBALS['TYPO3_DB'] .

Select

The Select statement is described in a little bit more detailed. The other examples will become shorter, but I am sure, you’ll able to adapt, if you know a bit about database statements.

So „Gimme all pages“ will simply be

If you are using this short syntax style to create your result sets, you have not much influence to the restrictions. So everything that is deleted or hidden (e.g. in the frontend) will not be selected. The only thing left you have to do is to iterate over the result set with e.g. foreach ($result->fetchAll() as $row)  …

Insert

Update

Delete

Conclusion

There are a couple of other functions, that I didn’t want to discuss here, either because they are more or less self explaining (e.g. ->count()) or in my opinion a kind of risk (e.g. -> truncate()). If you want to have more and detailed informations about this, check out the file typo3/sysext/core/Classes/Database/Connection.php which is responsible for all of the former stuff.

To be honest, I am a little bit unsure about this toolset. On the one hand, it could be a nice addition, if you need small statements. But on the other hand you’ll have to learn the complex way nevertheless as described in [1], because you have to walk that road latest when you need more control over your statements („more control“ as in „restrictions“ and „joins“).

Links

[1] Migrate from the TYPO3 database wrapper to the Doctrine DBAL syntax

Ein Gedanke zu „TYPO3 Doctrine DBAL convenience store

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.