Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Feature request: Database hooks #1275

Closed
nico87 opened this Issue Apr 23, 2012 · 3 comments

Comments

Projects
None yet
3 participants

nico87 commented Apr 23, 2012

Hi!

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.

Thank you.

Contributor

cryode commented Apr 23, 2012

What sort of things do you need to run pre- and post-query? Give us some examples.

nico87 commented Apr 24, 2012

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.

mikeytag added a commit to mikeytag/CodeIgniter that referenced this issue Apr 25, 2012

Contributor

narfbg commented Oct 23, 2012

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.

@narfbg narfbg closed this Oct 23, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment