Subclass of tgcSqlBuilder that helps to create SELECT sql-statements.
Subclass of tgcSqlBuilder that helps to create SELECT sql-statements.
Located in /tgcSqlBuilder/Select.php (line 38)
tgcSqlBuilder | --tgcSqlBuilder_Select
Constructor
Constructor
Add a GROUP BY statement.
Add a GROUP BY statement. How to call the method:
1 $sql = new tgcSqlBuilder_Select($dbc);
2
3 // add a GROUP BY for a tablename and a column, ASC
4 // as ASC is the default direction it doesn't have to be specified
5 $sql->addGroupBy('users', 'groupName');
6
7 // group by alias 'grpName', direction DESC
8 $sql->addGroupBy('grpName', null, SQLBUILDER_ORDER_DESC);
9
10 // group by column no. 2, direction ASC
11 $sql->addGroupBy(2);
The statements will be found in that order in the query, in which they have been added.
Add a WHERE statement.
Add a WHERE statement. Possible comparison operators are: SQLBUILDER_COMP_EQUAL, SQLBUILDER_COMP_NOT_EQUAL, SQLBUILDER_COMP_LESSER_THAN, SQLBUILDER_COMP_LESSER_EQUAL, SQLBUILDER_COMP_GREATER_EQUAL, SQLBUILDER_COMP_GREATER_THAN, SQLBUILDER_COMP_STARTSWITH, SQLBUILDER_COMP_CONTAINS, SQLBUILDER_COMP_ENDSWITH, SQLBUILDER_COMP_BETWEEN If none is specified then SQLBUILDER_COMP_EQUAL will be used. Possible logical expressions are: SQLBUILDER_LOGICAL_AND, SQLBUILDER_LOGICAL_OR If none is specified, then SQLBUILDER_LOGICAL_AND will be used. When you are using SQLBUILDER_COMP_BETWEEN, then specify $values as a numerical array with two values in correct order.
Add an ORDER BY setting.
Add an ORDER BY setting. The parameter $direction can be either SQLBUILDER_ORDER_ASC or SQLBUILDER_ORDER_DESC. If none is specified, then SQLBUILDER_ORDER_ASC will be used. You can also leave $column null, if you want to order by an alias.
1 $sql = new tgcSqlBuilder_Delete($dbc);
2
3 // ... ORDER BY alias1 ASC ...
4 $sql->addOrderBy('alias1');
5
6 // ... ORDER BY alias2 DESC ...
7 $sql->addOrderBy('alias2', null, SQLBUILDER_ORDER_DESC);
If a setting for this table/column exists, it will be overwritten.
Add a raw HAVING statement.
Add a raw HAVING statement. You can add a raw HAVING statement and define a logical operator. As default this is the logical AND.
Add a SELECT statement.
Add a SELECT statement. Optionally you can specify an alias for the column.
1 $sql = new tgcSqlBuilder_Select($dbc)
2 // this will add the following statement:
3 // SELECT MAX(users.userId) AS maxId, AVG(users.money) FROM ...
4 $sql->addRawSelect('MAX(users.userId)', 'maxId');
5 $sql->addRawSelect('AVG(users.money)');
If you call $sql->generateQuery() before you add a (raw) SELECT statement, a SELECT * FROM ... will be performed.
Add a raw WHERE statement.
Add a raw WHERE statement. You can add a raw WHERE statement and define a logical operator. As default this is the logical AND.
Add a SELECT statement.
Add a SELECT statement. Optionally you can specify an alias for the column.
1 $sql = new tgcSqlBuilder_Select($dbc)
2 // this will add the following statement: SELECT users.username AS name ...
3 $sql->addSelect('users', 'username', 'name');
If you call $sql->generateQuery() before you add a select statement, a SELECT * FROM ... will be performed.
Add a WHERE statement.
Add a WHERE statement. Possible comparison operators are: SQLBUILDER_COMP_EQUAL, SQLBUILDER_COMP_NOT_EQUAL, SQLBUILDER_COMP_LESSER_THAN, SQLBUILDER_COMP_LESSER_EQUAL, SQLBUILDER_COMP_GREATER_EQUAL, SQLBUILDER_COMP_GREATER_THAN, SQLBUILDER_COMP_STARTSWITH, SQLBUILDER_COMP_CONTAINS, SQLBUILDER_COMP_ENDSWITH, SQLBUILDER_COMP_BETWEEN If none is specified then SQLBUILDER_COMP_EQUAL will be used. Possible logical expressions are: SQLBUILDER_LOGICAL_AND, SQLBUILDER_LOGICAL_OR If none is specified, then SQLBUILDER_LOGICAL_AND will be used. When you are using SQLBUILDER_COMP_BETWEEN, then specify $values as a numerical array with two values in correct order.
Enable the distinct setting.
Enable the distinct setting.
Enable the distinct setting.
Enable the distinct setting.
Generate the sql-statement.
Generate the sql-statement. This method generates a query based on the object-information and returns it as a string.
1 $sql = new tgcSqlBuilder_Select($dbc);
2 $query = $sql->generateQuery();
Remove a GROUP BY statement.
Remove a GROUP BY statement.
Remove a WHERE statement.
Remove a WHERE statement. If you don't specify any parameter, then all WHERE information will be removed. If you specify a tablename and a columnname, then this specific ORDER BY setting will be removed.
Remove an ORDER BY setting.
Remove an ORDER BY setting. If you don't specify any parameter, then all ORDER BY information will be removed. If you specify a tablename and a columnname, then this specific ORDER BY setting will be removed.
Remove the raw WHERE statements, that have been stored so far.
Remove the raw WHERE statements, that have been stored so far.
Remove a raw SELECT statement.
Remove a raw SELECT statement. If call the method without parameters, all raw SELECT statements that have been stored so far will be removed. If you call the method with parameter, then the specified SELECT statement will be removed.
1 $sql = new tgcSqlBuilder_Select($dbc);
2 $sql->addRawSelect('MAX(users.userId)', 'maxId');
3 $sql->addRawSelect('AVG(users.money)');
4
5 // remove a specific raw SELECT statement by alias
6 $sql->removeRawSelect('maxId');
7
8 // remove all raw SELECT statements
9 $sql->removeRawSelect();
Remove the raw WHERE statements, that have been stored so far.
Remove the raw WHERE statements, that have been stored so far.
Remove a SELECT statement.
Remove a SELECT statement. If call the method without parameters, all SELECT statements that have been stored so far will be removed. If you call the method with one or two parameters, then the specified SELECT statement will be removed.
1 $sql = new tgcSqlBuilder_Select($dbc);
2 $sql->addSelect('users', 'userId');
3 $sql->addSelect('users', 'username', 'name');
4 $sql->addSelect('users', 'email', 'mail');
5
6 // remove a specific SELECT statement by alias
7 $sql->removeSelect('name');
8
9 // remove a specific SELECT statement
10 $sql->removeSelect('users', 'userId');
11
12 // remove all SELECT statements
13 $sql->removeSelect();
Remove a WHERE statement.
Remove a WHERE statement. If you don't specify any parameter, then all WHERE information will be removed. If you specify a tablename and a columnname, then this specific ORDER BY setting will be removed.
Reset the object's whole information.
Reset the object's whole information.
Set a LIMIT for the query.
Set a LIMIT for the query. Example:
1 $sql = new tgcSqlBuilder_Select($dbc);
2
3 // set a limit of 15 rows starting from offset 30
4 $sql->setLimit(30, 15);
5
6 // set a limit of 20 rows (starting from offset 0)
7 $sql->setLimit(20);
Unset the current LIMIT information.
Unset the current LIMIT information.
Inherited From tgcSqlBuilder
tgcSqlBuilder::tgcSqlBuilder()
tgcSqlBuilder::addTable()
tgcSqlBuilder::escape()
tgcSqlBuilder::generateQuery()
tgcSqlBuilder::removeTable()
tgcSqlBuilder::reset()
Documentation generated on Fri, 19 Nov 2004 23:54:05 +0100 by phpDocumentor 1.2.3