CodeIgniter Forums
Events::on('DBQuery') - Printable Version

+- CodeIgniter Forums (
+-- Forum: Using CodeIgniter (
+--- Forum: General Help (
+--- Thread: Events::on('DBQuery') (/showthread.php?tid=78400)

Events::on('DBQuery') - okatse - 01-14-2021


When the system executes a query I want to parse the query and modify it. I want to create a BeforeExecuteQuery method or event. 

An example: 
The users => ID, Name, Password table 

PHP Code:
$users = new \ App\Models\UserModel(); 
= $ users->findAll (); 
// select ID, Name, Password from users 

I want the Password field to always be removed from query

For now it's catching the query like this, but I can't change it
Events::on('DBQuery', 'My_parser_query');

RE: Events::on('DBQuery') - kleber - 01-19-2021

The ideal would be to create a new function in the model with the db fields as parameters. Or I would add a select before findAll with only the fields I want to display. There is no need for an event for this.

RE: Events::on('DBQuery') - okatse - 01-20-2021

Modify all methods present and all future ones - to delete one field ??? One event that makes sure that such a field is not returned in any method is better