change statement before execute

How to change sql statement before execute query?



18.2k

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



18.2k

Try with this http://docs.phalconphp.com/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: http://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



18.2k

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.