CI_DB_driver::protect_identifiers()

protect_identifiers($item[, $prefix_single = FALSE[, $protect_identifiers = NULL[, $field_exists = TRUE]]])

Parameters:
  • $item (string) – The item to work with
  • $prefix_single (bool) – Whether to apply the dbprefix even if the input item is a single identifier
  • $protect_identifiers (bool) – Whether to quote identifiers
  • $field_exists (bool) – Whether the supplied item contains a field name or not
Returns:

The modified item

Return type:

string

Takes a column or table name (optionally with an alias) and applies the configured dbprefix to it.

Some logic is necessary in order to deal with column names that include the path.

Consider a query like this:

SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table

Or a query with aliasing:

SELECT m.member_id, m.member_name FROM members AS m

Since the column name can include up to four segments (host, DB, table, column) or also have an alias prefix, we need to do a bit of work to figure this out and insert the table prefix (if it exists) in the proper position, and escape only the correct identifiers.

This method is used extensively by the Query Builder class.

doc_CodeIgniter
2016-10-15 16:31:07
Comments
Leave a Comment

Please login to continue.