Stud.IP  5.4
 All Data Structures Namespaces Files Functions Variables Groups
SQLQuery Class Reference

Public Member Functions

 __construct (string $table, string $query_name= '')
 
 select ($select, $statement=null)
 
 join ($alias, $table=null, $on= '', $join= 'INNER JOIN')
 
 where ($name, $condition=null, $parameter=[])
 
 having ($name, $condition=null, $parameter=[])
 
 parameter ($param, $value=null)
 
 removeWhereCondition ($name)
 
 groupBy ($clause)
 
 orderBy ($clause)
 
 limit ($start, $end=null)
 
 count ()
 
 fetchAll ($sorm_class_or_column=null)
 
 show ()
 

Static Public Member Functions

static table (string $table, string $query_name= '')
 

Data Fields

 $settings
 
 $name = ''
 

Protected Member Functions

 getQuery ()
 
 getPrimaryKey ()
 

Detailed Description

Class SQLQuery This class is to MANAGE a query that is maybe more complex than a standard sql-query. You can easily add filters, joins and additional select-parts.

$query = SQLQuery::table("auth_user_md5") ->join("seminar_user", "seminar_user.user_id = auth_user_md5.user_id") ->join("seminar_inst", "seminar_inst.seminar_id = seminar_user.Seminar_id") ->where("seminar_inst.institut_id = :institut_id",array('institut_id' => $inst->getId())); if (Request::get("status") { $query->where("auth_user_md5.status = :status", array('status' => Request::get("status")); } if ($query->count() <= 500) { $user_data = $query->fetchAll(); } else { PageLayout::postInfo(_("Geben Sie mehr Filter ein.")); }

Constructor & Destructor Documentation

__construct ( string  $table,
string  $query_name = '' 
)

Constructor of the query. A main table is needed.

Parameters
string$table: a database table
stringname :

Member Function Documentation

count ( )

Fetches the number of entries of the resultset.

Returns
integer.
fetchAll (   $sorm_class_or_column = null)

Fetches the whole resultset as an array of associative arrays. If you define a sorm_class the result will be an array of the sorm-objects.

Parameters
$sorm_class_or_column: column name, a class of SimpleORMap or null for associative array.
Returns
array of arrays or array of objects or array of values.
getPrimaryKey ( )
protected

Fetches the primary key of the table and returns it as an array.

Returns
array : primary key as array("column1", "column2")
getQuery ( )
protected

Constructs a query string for a prepared statement without the SELECT part.

Returns
string
groupBy (   $clause)

Sets the grouping of the resultset.

Parameters
string$clause: the clause to sort after like "auth_user_md5.user_id"
Returns
$this
having (   $name,
  $condition = null,
  $parameter = [] 
)
join (   $alias,
  $table = null,
  $on = '',
  $join = 'INNER JOIN' 
)

Joins a table to the query. You can omit $table and just call join($tablename, $on, $join) if you don't need an alias.

Parameters
$alias: table-name or an alias.
null$table: optional table name. Use this if you want to use an alias.
string$on: any condition like "t1.user_id = t2.id"
string$join: type of joining "INNER JOIN" or "LEFT JOIN"
Returns
$this
limit (   $start,
  $end = null 
)

Limits the resultset of the query.

Parameters
integer$start
null | integer$end
Returns
$this
orderBy (   $clause)

Sets the order of the resultset.

Parameters
string$clause: the clause to sort after like "Vorname ASC, position DESC"
Returns
$this
parameter (   $param,
  $value = null 
)

Sets one or more parameter for this query.

Parameters
array | string$param: associative array or string
null | string$value: value of parameter when $param is a string
removeWhereCondition (   $name)

Removes a formerly defined where condition identified by its name.

Parameters
$name: the name of the where-condition that was defined in where-method..
Returns
$this
select (   $select,
  $statement = null 
)
show ( )

Shows the query that would be executed in the method fetchAll

Returns
string : sql query
static table ( string  $table,
string  $query_name = '' 
)
static
where (   $name,
  $condition = null,
  $parameter = [] 
)

Adds a condition to the query. Any conditions will get concatenated by AND.

Parameters
$name: the name of the condition. Use any name. It will be treated as an identifier.
null$condition
array$parameter
Returns
$this

Field Documentation

$name = ''
$settings
Initial value:
= [
'table' => ''

The documentation for this class was generated from the following file: