PEAR Handbuch | ||
---|---|---|
Zurück | Nach vorne |
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..
Raw Database Queries
Sends a raw Query to the database
Beispiel 1. raw Queries on the database
|
Adding and removing Items from select query
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.
Beispiel 2. Adding select statements
|
This would execute the following SQL statements,
Beispiel 3. Resulting SQL
|
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)
Adds conditions to the Where part of the query
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.
Beispiel 4. Adding Where Statements
|
This would execute the following SQL statements,
Beispiel 5. Resulting SQL
|
Sets the limit of a query
Sets the limit range. Calling this without any arguments clears the range
Beispiel 6. Setting the Limit
|
This would execute the following SQL statements,
Beispiel 7. Resulting SQL
|
Appends to the 'order by' part of the query
Appends an Order condition. Calling this without any arguments clears the order
Beispiel 8. setting the order by
|
This would execute the following SQL statement,
Beispiel 9. Resulting SQL
|
Appends a to the 'group by' part of the query
Appends a Group condition. Calling this without any arguments clears the Group Condition
Beispiel 10. Setting the Group by
|
This would execute the following SQL statement,
Beispiel 11. Resulting SQL
|
Zurück | Zum Anfang | Nach vorne |
Modifying the database | Nach oben | Automatic Table Linking |