User Guide | Querying SQL Results

A guide to returning data from SQL queries returned by flexi auth functions.

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.

// Example #1: Chaining CodeIgniters 'result()' function.

$this->flexi_auth->get_users()->result();
// Example #2: Chaining CodeIgniters 'row_array()' function.

$this->flexi_auth->get_users()->row_array();
// Example #3: Returning the query object without applying a result function.

$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.

// Example #1: Returning CodeIgniters 'result()' query data using alternative syntax.

$this->flexi_auth->get_users_result();
// Example #2: Returning CodeIgniters 'row()' query data using alternative syntax.

$this->flexi_auth->get_users_row();
// Example #3: Returning CodeIgniters 'result()' query data using alternative syntax.

$this->flexi_auth->get_users_array();
// Example #4: Returning CodeIgniters 'row_array()' query data using alternative syntax.

$this->flexi_auth->get_users_row_array();
// Example #5: Returning CodeIgniters 'num_rows()' query data using alternative syntax.

$this->flexi_auth->get_users_num_rows();
// Example #6: Returning the query object without applying a result function.

$this->flexi_auth->get_users();