General Documentation:
The main object in this collection is The
`ROWSET`('crdb_rowset' in the class file) Object.
A rowset object represents a set of rows from a single table,or more in case you
are using joins.
An SQL statement may be seen as comprising of three parts.
1.First part specifies an operation ,like if it is a SELECT or UPDATE or DELETE
operation.
2.Second part specifies the database tables and how to join them.
3.Third part specifies a condition that must be satisfied by a row in these
joined tables,to include it in the operation specifed in the first part.
A rowset object ,only requires the second part, the first and third part may be
added later.
Basic rowsets ( without the third ,ie the condition part):
<?php $rowset = $crdb->table_name(); ?>
returns a rowset with all rows from table 'table_name'.
<?php $rowset = $crdb->_join->table_name_1('alias_1')->table_name_2('alias_2')...->_end(); ?>
returns a rowset with all the tables 'table_name_1' ,'table_name_2'....
joined using a normal join.
<?php $rowset = $crdb->_left_join->table_name_1('alias_1')->table_name_2('alias_2')...->_end(); ?>
returns a rowset with all the tables 'table_name_1' ,'table_name_2'....
joined using a left join. _right_join also can be used.
(The columns used for joins have to be specified in an array passed to the
constructor of the CRDB object.This info can be accessed from the tables metadata,if
foriegn keys are defined.But for small projects no one seems to use them. )
Specifing Conditions on a rowset:
once a rowset is created ,you can add more conditions ,ie the 'WHERE' part
of an SQL statement as
<?php $rowset=$rowset->column_1('value_one')->column_2('value_2')->....; ?>
Each call to a function,after adding the new condition , returns the $rowset
object(a copy actually, with the new where condition added) .So you
can chain any number of conditions like this.
To specify an 'OR' somewhere in the conditions add a call to or()
member function like
<?php $rowset->column_1('value_one')
->column_2('value_2')
->or()
->column_3('value_3'); ?>
To sort the rows in a rowset call the 'order_by' or 'desc_order_by'
member functions as ,
<?php $rowset->order_by()->id; //sort in ascending order using column `id` ;?>
or
<?php $rowset->desc_order_by()->id; //sort in descedning order using column `id`; ?>
Please note that order_by() does not return a rowset immediatly,only after specifying
a column the rowset is returned ie $rowset->order_by() does not return a rowset but
$rowset->order_by()->id does.
Operations on ROWSETs:
<?php $name=$rowset->column_name; ?>
Returns the value in the column 'column_name' in the first row of the rowset.
<?php $rowset->column_name= 'teststring'; ?>
Sets the value for column 'column_name' to 'teststring' for ALL rows in
rowset.Once the rowset is made joining many tables the `column_name` can
refer to a column in any of those tables.This change is reflected in
database immediatly.(please note when joining ,you have to refer
column names by prepending them with table name and an underscore.that way
the 'name' column in `user` table which is aliased as 'u' becomes 'u_name').
<?php foreach($rowset as $k=>$v) ; ?>
Iterate through all the rows in rowset.column values accessed as
<?php $v->column_name ?> for each iteration.
<?php $rowset->delete(); ?>
Deletes all rows from rowset.This will affect all the tables from
which the rowset is created.