• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add "global" where clause to any SQL-Query

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!

Check out Active Record caching.
It allows you to store pieces of queries just like your 'where owner=$user_id' piece.

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?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.