Database Events
The Database classes contain a few Events that you can tap into inorder to learn more about what is happening during the database execution. These events canbe used to collect data for analysis and reporting. The Debug Toolbaruses this to collect the queries to display in the Toolbar.
The Events
DBQuery
This event is triggered whenever a new query has been run, whether successful or not. The only parameter isa Query instance of the current query. You could use this to display all queriesin STDOUT, or logging to a file, or even creating tools to do automatic query analysis to help you spotpotentially missing indexes, slow queries, etc. An example usage might be:
- // In Config\Events.php
- Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
- // Collect the queries so something can be done with them later.
- public static function collect(CodeIgniter\Database\Query $query)
- {
- static::$queries[] = $query;
- }
当前内容版权归 codeigniter4 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 codeigniter4 .