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

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Events::on('DBQuery') (/thread-78400.html)



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

Hi 

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(); 
$res 
= $ 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