Stud.IP  5.4
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, ?int $max_results=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()

__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()

count ( )

Fetches the number of entries of the resultset.

Returns
integer.

◆ fetchAll()

fetchAll (   $sorm_class_or_column = null,
?int  $max_results = 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.

T of SimpleORMap

Parameters
class-string<T>|string|null$sorm_class_or_column : column name, a class of SimpleORMap or null for associative array.
int | null$max_resultsMaximum number of results to return
Returns
array[]|T[]|mixed[] arrays or array of objects or array of values.
Exceptions
OverflowExceptionif number of found rows is greater than $max_results

◆ getPrimaryKey()

getPrimaryKey ( )
protected

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

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

◆ getQuery()

getQuery ( )
protected

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

Returns
string

◆ groupBy()

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()

having (   $name,
  $condition = null,
  $parameter = [] 
)

◆ join()

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()

limit (   $start,
  $end = null 
)

Limits the resultset of the query.

Parameters
integer$start
null | integer$end
Returns
$this

◆ orderBy()

orderBy (   $clause)

Sets the order of the resultset.

Parameters
string$clause: the clause to sort after like "Vorname ASC, position DESC"
Returns
$this

◆ parameter()

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()

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 (   $select,
  $statement = null 
)

◆ show()

show ( )

Shows the query that would be executed in the method fetchAll

Returns
string : sql query

◆ table()

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

◆ where()

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

$name = ''

◆ $settings

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

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