How can I wrapp odbc calls without modifing the way I do the calls in PHP?

Hi I am looking for a clean way to wrapp all my odbc calls with some error handling and logs without modifying all the code, but do it in an external way through overiding / define() / or reflexion. I dont knwo what to use or how to use it.

My application is actually using odbc directly in the code, and there is a lot of it, in class methods or in scripts directly.
We are currently trying to improve our performances and code quality, and without having logs, it is hard.
What I’d like to dot is to override ODBC by putting a decorator around it’s methods. Then this decorator execute ODBC, log queries / errors ect.

As you may think, it would be easier to just go over all the code and log. I could do that, but I am currently looking at this way to do because I don’t know to do it yet. It would be so much faster also to show my manager the avantages of having our own implementation of odbc wrapper.

Also i could just use it on local environement to find out wich queries are called multiple times or in loop.

I am just looking to do so for odbc_exec, odbc_prepare and odbc_execute. So no need to change the engine it self I believe

Any person having a snippet to share or an idea to solve this?