Welcome Guest, Not a member yet? Register   Sign In
Add "global" where clause to any SQL-Query
#1

[eluser]Unknown[/eluser]
Hi there!
Does anyone know if it's possible to add a Where-Clause which will be added to any SQL-Query automatically?

For example: I want to make sure my users select/update/delete only their DB-data. So for Security I added to all my SQL-Querys:

$this->db->where('owner', $user_id);


For simplicity and I don't forget to add this where-clause somewhere, is it possible to setup somehow a "globally" valid where-statement, which is added to any sql-query by default? This doesn't need to be application-wide, but at least Model-wide

Thanks for any hints!
#2

[eluser]mddd[/eluser]
Check out Active Record caching.
It allows you to store pieces of queries just like your 'where owner=$user_id' piece.
#3

[eluser]Unknown[/eluser]
great thanks a lot!

actually this does exactly what I asked for ... but after testing it, I see that I can't actually work this way ;-) as this where-clause is now added to ALL queries (yeah, i know I asked for it Wink - so also to queries which don't have an "owner"-column like the CI-"session"-table, or e.g. I'm using ION_AUTH which uses Joins so a simple "where(‘owner’, $user_id)" will end up in an db-error: "Column 'owner' in where clause is ambiguous" (because of using joins).

any other idea I can add this now not "globally" but only Model-wide, so it is only effect my Model-Queries?




Theme © iAndrew 2016 - Forum software by © MyBB