We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

change statement before execute

How to change sql statement before execute query?


You mean $phql in executeQuery($phql)?

edited Jul '14

i would like add an event where is possible add a 'where' clause before execute statement. thus, it is possible create multi-tenant control


Try with this https://docs.phalcon.io/es/latest/reference/events.html I've not tested much things that Phalcon offers, but I've read it and not seems difficult. The only part is at the beginning, with the "can be as verbose as we need it to". Try copy-pasting the beforeQuery method and send an echo with a die (for example) to test that it works. Sorry not being of more help. (PD: no idea what is multi-tenant control xD)

Thanks David!

I already tested this event, but i cannot set modified sql into $connection.

In this article explains multi-tenant concept: https://blog.techcello.com/2012/07/database-sharding-scaling-data-in-a-multi-tenant-environment/

In my case i am using the item: Customization in the data layer


Ah, database sharding, now it sounds more clear to me (but a little, I didn't learnt it in deep). The last thing that I can tell you is: did you try to return a new $connection with the modified sql inside? Maybe that works.