Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Bye bye $GLOBALS['TYPO3_DB']
1. Real Values.
Bye bye $GLOBALS['TYPO3_DB']
Start using Doctrine DBAL in your Extension
2. Real Values.
About
▪ Senior TYPO3 Developer @ sitegeist
▪ Working with TYPO3 since version 3.8
▪ TYPO3 developer since 2004
▪ TYPO3 core developer since 2015
▪ Cartographer, Food Blogger and
Square Dancer
▪ Twitter: @buccaneer23
Jan Helke
4. Real Values.
• Replacement of $GLOBALS['TYPO3_DB']->exec_SELECTgetRows
• Because MySQL only (or slow due to DBAL Extension)
• Doctrine supports multiple database vendors
• MySQL SAP Sybase SQL Anywhere
• Oracle SQLite
• Microsoft SQL Server Drizzle
• PostgreSQL
Management Summary
Why switch to Doctrine DBAL?
5. Real Values.
Your benefits
• Agencies
• Potential TYPO3 customer base to all non-MySQL users.
• Customers
• A reliable industry standard
• Developers
• More fun because of easy API and create beautiful code.
Management Summary
6. Real Values.
What about Extbase extensions?
•If you use just native Extbase function
•We got you covered. Extbase QueryBuilder is already
converted
•If you create custom / overwrite native functions using
$GLOBALS['TYPO3_DB'] (e.g. in your repositories)
•Stay awake and pay attention
Management Summary
7. Real Values.
But what about performance?
Tests showed:
•On a nearly perfect configured system:
- 0.5 percent
•On a random casual configured system:
+ 3.0 percent
Management Summary
8. Real Values.
It's dead Jim (was "Deadline")
• $GLOBALS['TYPO3_DB'] will only work until TYPO3 8 LTS
•Is already removed from master since April 2017
•Can only be reinstalled with
composer require friendsoftypo3/typo3db-legacy
•No back-port to TYPO3 7 LTS
Management Summary
9. Real Values.
End of management overview
• If you just wanted to know what the state of play is and how to scare your
boss, these were the facts.
Go and spread fear!
• If you want to migrate right now with your project
Stay!
Warning: Next slides might contain some chunks of code.
Management Summary
10. Real Values.
Query Builder
•Swiss army knife for database handling
•Knows the database vendor for every table
•Tables can be stored on different vendors databases
•Needs to be initialized for every table
$queryBuilder =
GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_log');
Developer introduction
11. Real Values.
Simple select [past]
Short example for warming up.
$rows = $this->getDatabaseConnection()
->exec_SELECTgetRows(
'uid',
'pages,
'pid=' . $pid
);
Developer introduction
12. Real Values.
Simple select [future][now]
$rows = $queryBuilder
->select('uid')
->from('pages')
->where(
$queryBuilder->expr()->eq( <---|
'pid', |
$queryBuilder |
->createNamedParameter( |-- read: "where 'pid' = $pid"
$pid, | we will come to that later
PDO::PARAM_INT |
) <---|
)
)
->execute()
->fetchAll();
If you want only a single row, just ->fetch() it.
Developer introduction
13. Real Values.
Nesting conditions [past]
$rows = $this->getDatabaseConnection()
->exec_SELECTgetRows(
'uid, userid, action, tstamp, log_data',
'sys_log',
'type = 1 ' .
' AND (action=1 OR action=3)'
);
Developer introduction
19. Real Values.
Final highlight
All of you Extbase Query Builder dev know the ultimate pain.
Doctrine DBAL has the answer.
echo $queryBuilder
->select('*')
->from('sys_history')
->getSQL();
If you get something like "dcValue1" in some clause, have a look at
$queryBuilder->getParameters.
Developer introduction
20. Real Values.
Restriction builder
•The new "enableFields" magic
•Handled by the query builder
•Context related restriction container
•Show everything regardless of hidden, deleted ...
$queryBuilder
->getRestrictions()
->removeAll();
Developer introduction
21. Real Values.
Boundless restrictions
•Create your own restriction set
•Have a look at
TYPO3CMSCoreDatabaseQueryRestrictionDefaultRestrictionContainer
$queryBuilder
->setRestrictions(OwnNamespaceCustomRestrictionContainer);
Developer introduction
24. Real Values.
Sources
Docs » TYPO3 API » Database Access
http://bit.ly/2wWhBxp
(Thanks to Christian Kuhn for this awesome documentation)
My Blog
http://bit.ly/2ytwSXt
Sources