Querying SQL Results
Customising SQL Statements Index |
Defining Custom SQL Statements |
Building Custom SQL Queries
Returning Query Results by Chaining CodeIgniter Functions
flexi auth provides many SQL SELECT query functions that return query objects using CodeIgniters Active Record class.
To return data from the query objects, CodeIgniters query result functions ('result()', 'row()' etc.) can be directly chained to the returned object.
Examples
Note: These examples use the 'get_users()' function as an example SQL SELECT query function.
$this->flexi_auth->get_users()->result();
$this->flexi_auth->get_users()->row_array();
$this->flexi_auth->get_users();
Returning Query Results using an Alternative Syntax
To offer an alternative and slightly tidier syntax, flexi auth allows you to automatically return the query data type that you want by defining so via the functions actual name.
This method still uses CodeIgniters query result functions, but simply does the chaining for you, returning the exact same data.
Alternative Syntax
Note: The following 'xxx' values represent the name of the flexi auth function that is being chained.
CodeIgniter Function |
Alternative Syntax |
Description |
xxx->result() |
xxx_result() |
Returns a query result as an array of objects, or an empty array on failure. |
xxx->row() |
xxx_row() |
Returns a single result row as an object. If the query has more than one row, it returns only the first row. |
xxx->result_array() |
xxx_array() |
Returns a query result as a pure array, or an empty array when no result is produced. |
xxx->row_array() |
xxx_row_array() |
Returns a single result row as an array. If the query has more than one row, it returns only the first row. |
xxx->num_rows() |
xxx_num_rows() |
Returns the number of rows returned by a query. |
Notes
Using the alternative syntax can be used on virtually all SQL SELECT functions within the library.
Functions that are compatible are defined via each functions details described in this user guide.
Examples
Note: These examples use the 'get_users()' function as an example SQL SELECT query function.
$this->flexi_auth->get_users_result();
$this->flexi_auth->get_users_row();
$this->flexi_auth->get_users_array();
$this->flexi_auth->get_users_row_array();
$this->flexi_auth->get_users_num_rows();
$this->flexi_auth->get_users();