-
Notifications
You must be signed in to change notification settings - Fork 5
Creating queries
nik-os edited this page Sep 19, 2014
·
2 revisions
We create class \samson\activerecord\dbQuery
for writing database queries. dbQuery() is shortcut for receiving \samson\activerecord\dbQuery object instance.
-
cond([attribute], [value], [relation] )
- add condition to query- [atribute] - attribute name in the search term
- [value] - attribute value in the search term
- [relation] - type of relations between the arguments of conditional group of the query to the database. Constatnt of class
\samson\activerecord\dbRelation
. Default -dbRelation::EQUAL
;
-
exec()
- execute request to DB and return array of query result. If we set parametr
$result = array(); dbQuery('tableName')->exec($result);
Function returns ```true``` or ```false``` dependent on result of the query and set to ```$result``` query result.
It usefull in ```if``` constructions, such as
$result = array(); if (dbQuery('tableName')->exec($result)) { //doing something with query result }
* ```first()``` - doing the same as ```exec()```, but it return the first record from query result.
* ```order_by([attribute], [direction])``` - add sort parametr to request
* ```group_by([attribute])``` - add ```GROUP BY``` to request
* ```fields()``` -
* ```join()``` -