Advanced Filters

Advanced Filters --  Advanced Filters - ::query(), ::SelectAdd(), ::whereAdd(), ::Limit(), ::OrderBy(), ::GroupBy(),

More advanced Querying

The basic features allow most simple queries to be done very quickly, however building more complex queries can be done using the methods listed below, which append or set conditions that build the query. You will find that there is a fine balance between using these builder methods and just using raw SQL.

The DB_DataObject class does not handle JOIN queries directly for the simple reason that it is designed to simplify the use of databases, and make the code that access them clear and easy to read. Having experimented with a Join Version, it became very clear that this did not fulfill either of these goals, and made the resulting code more difficult to read, debug and understand. So in reality it is best to use the raw query() method to do joined queries..

::query()

Raw Database Queries

::query (string query)

Sends a raw Query to the database

::selectAdd()

Adding and removing Items from select query

::select ([string Select Items])

By default a select query will request all items '*', to change this behavior you can first call selectAdd() without any arguments to clear the current request and then add the specific items you require.

This would execute the following SQL statements,

You can also set up a default selection query by adding SelectAdd() method calls in the object initialization method (the one with the same name as the class)

::whereAdd()

Adds conditions to the Where part of the query

::whereAdd ([string Where [, string OR]])

Adds items to the where part of a SQL query. Calling this without any arguments clears, the where condition. The default behavior is to add 'AND' queries, send the string 'OR' to append OR conditions.

This would execute the following SQL statements,

::limit()

Sets the limit of a query

::limit ([int (Limit Range Start or Number) [, int (Limit Range Number)]])

Sets the limit range. Calling this without any arguments clears the range

This would execute the following SQL statements,

::orderBy()

Appends to the 'order by' part of the query

::orderBy ([string Order])

Appends an Order condition. Calling this without any arguments clears the order

This would execute the following SQL statement,

::groupBy()

Appends a to the 'group by' part of the query

::groupBy ([string Group])

Appends a Group condition. Calling this without any arguments clears the Group Condition

This would execute the following SQL statement,