Welcome Guest, Not a member yet? Register   Sign In
Query Builder selectExclude()

When querying large tables or tables with multiple joins, it is sometimes necessary to return many if not all columns. However, it is sometimes necessary to not return a few columns which may hold sensitive data. Rather than typing a huge select statement, or trying to unset the fields after generating results, I propose that a Query Builder method be added to handle this. This can additionally be useful when building APIs. For example, pulling account data while excluding fields such as password.

There are a few methods to accomplish this.

Method 1:
After result set generation, pass the result array through a loop to unset the excluded fields. This will prevent the columns from being returned at all. This method adds processing overhead, but can significantly reduce memory consumption for large result sets.

Method 2:
Looking back at https://github.com/codeigniter4/CodeIgni...ssues/1169 an additional benefit of adding a "NULL AS `exclude`" to a "SELECT *" statement will return a null value in the results set. This method currently works in CI4, but is a pretty dirty workaround query wise since MySQL will return two columns with the same name one with the value and one as NULL. CI4 will overwrite the first value with NULL so long as the NULL portion of the statement comes after the rest of the select statement. This method reduces processing overhead but can eat memory on large result sets.

Thanks CI4 Team!

Or just run your sql query using the standard way and exclude the fields.

You can mix Query Builder and the CI db query together.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

Theme © iAndrew 2016 - Forum software by © MyBB