Modify all queries in Zend\Db (add where)

120 views Asked by At

I need to modify all queries that are executed through Zend\Db before sending them to DB.

Basically it needs to add additional WHERE statement to all selects, updates and deletes and additional column and value in inserts.

I was thinking about writing my own TableGateway feature for that, the problem is that I would like to avoid being restricted to TableGateway alone and have this functionality while using Zend\Db\Adapter and TableGateway at the same time.

2

There are 2 answers

0
Adam On BEST ANSWER

I have ended up writing custom db adapter that handles all the logic. I'll probably share it as an open source if I'll have a time to clean up the code.

1
Thomas Dutrion On

You can have a look at some of the events dispatched from the table gateway if that make sense in your context: http://framework.zend.com/apidoc/2.4/namespaces/Zend.Db.TableGateway.Feature.EventFeature.html

There is a preSelect event that is triggered and which you can probably listen to.