You can clone with
No one assigned
Is it a clever feature to have database hooks (like post_db_connection, pre_query, post_query)?
This feature would be really useful to me (as well as other developers) if there aren't other ways to change the DB behavior in runtime.
What sort of things do you need to run pre- and post-query? Give us some examples.
I'm actually connecting to a MySQL server without selecting a DB. That's because I run queries on multiple DBs using a single connection and typing the DB name directly in the query.
As the 'dbprefix' config var allows me to add a prefix only to the table names, I've made a small 'hack' to CI core wich adds a prefix to the DB name aswell. That's because on the same MySQL server I've got both testing and production DBs. In this way, I can switch between testing and production DBs by changing a single var in CI's config (testing and production sites are on two different domains of course).
Now, It would be beautiful for me to get those hooks because I could run a custom trasformation before each query to setup the proper DB name (replacing a 'placeholder' in this case).
Moreover, it should be useful to check if the DB connection is available just after the DB initialization. In this way, I can redirect the user to a maintenance page in case of a non-available connection. Actually I'm doing this in the "post_controller_constructor" hook.
Added hooks for pre/post db connect and pre/post query (including sim…
…ple_query) fixes #1275
Running hooks on every database query is a BAD idea.
I guess an init-like procedure to be run after initializing the database connection could be implemented, but it's not going to happen via a hook.