Definition at line 39 of file grouped_query.inc.
◆ __construct()
GroupedQuery::__construct |
( |
|
$class, |
|
|
|
$constraints = "" , |
|
|
|
$groupBy = "" |
|
) |
| |
◆ create()
static GroupedQuery::create |
( |
|
$class, |
|
|
|
$constraints = "" , |
|
|
|
$groupBy = "" |
|
) |
| |
|
static |
◆ execute()
GroupedQuery::execute |
( |
| ) |
|
Reimplemented from AbstractQuery.
Definition at line 55 of file grouped_query.inc.
66 $order_by_idx = strpos(strtoupper($this->
constraints),
"ORDER BY");
67 if ($order_by_idx !==
false)
69 $orderBy = substr($this->
constraints, $order_by_idx);
74 $fields = $prototype->getFieldList();
78 $query =
"SELECT $fields FROM {$prototype->table} {$this->constraints} ".$prototype->getIdentityConstraint().
" $orderBy";;
85 $useFormat = preg_match(
"/^[A-Za-z0-9_]*$/", $field) ? false :
true;
91 $result = $db->prepare($query);
92 $result->execute($this->
params);
94 while($line = $result->fetch())
97 $item->populate($line);
98 $val = ($useFormat) ? $item->format($field) : $item->get($field);
100 $items[$val][] = $item;
105 catch(PDOException $e)
107 $err =
"groupedQuery() failed - " . $e->getMessage();
constraints($constraints)
Sets the constraint clause for the Query.
filter($filter)
Sets a filter to constrain the fields retrieved when the query is executed.
params($params)
Sets the bound parameters array.
static getConnection()
Retrieves a reference to the global database connection.
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
◆ executeValue()
GroupedQuery::executeValue |
( |
|
$func | ) |
|
Query the database to calculate aggregate values by grouping.
The database table associated with the specified class is used as the source for the data.
- Parameters
-
string | $func | the value or function to retrieve |
- Returns
- array an associative array of group values to calculated aggregate values
Definition at line 122 of file grouped_query.inc.
127 $this->
constraints .=
" ".$prototype->getIdentityConstraint();
129 $query =
"SELECT {$this->groupBy}, $func as result FROM {$prototype->table} {$this->tableAlias} {$this->constraints} GROUP BY {$this->groupBy}";
139 $result = $db->prepare($query);
140 $result->execute($this->
params);
142 while ($row = $result->fetch())
149 catch(PDOException $e)
151 $err =
"Query::executeValue() failed - " . $e->getMessage();
◆ groupBy()
GroupedQuery::groupBy |
( |
|
$groupBy | ) |
|
◆ $groupBy
The documentation for this class was generated from the following file: