PHP Classes

File: readme.txt

Recommend this page to a friend!
  Classes of Tom Schaefer  >  QDataObject  >  readme.txt  >  Download  
File: readme.txt
Role: Documentation
Content type: text/plain
Description: README
Class: QDataObject
Access MySQL query results as objects
Author: By
Last change:
Date: 13 years ago
Size: 7,565 bytes


Class file image Download
This wrapper dynamically builds a data object from a mysql resource.
It dynamically provides set, get, has, is, len, typ, of and add prefixed methods for header and data values.

2-letter-prefixed methods and has-prefixed methods always return a boolean statement;
3-letter-prefixed methods usually get or set data.
set-methods put data into the object once.
add-methods are able to push data at the end of an object property section.

set and add methods are bound to the data properties,

is, of, len, typ methods are are object header specific,

has and get switch between the data and header properties automatically.

This means:

$dataObject = new QDataObject($resource); // here the mysql resource goes into the object

Your query result set ($resource) contains following columns from a sql query like this:

d.department_id as depid,

FROM md_employees e
LEFT JOIN md_departments d
ON e.department_id=d.department_id

NOTE! For getting it working correctly, you have to write down the column names.
Using the asterisk * sign leads to errors if the columns of joined tables are
not unique. You can use an alias for getting unique columns.

The data object provides automatically following methods (You need not write them!!!)
and is behaving like a *data list object*:








and so on

The data object does a bit more. It provides some resource header information which
you can get by following methods:


Per definition a single row result is the smallest possible list, which means it is
a list with only one object. By this convention addressing a row becomes quite simple.
If you have a data object with one entry then you can get it like this.
which is already the same as

If you have a list of objects then you can get a list from a single column by
using following command:
$dataObject->getListByPosition(6) // means: get the list of all values from column 6

If you know a specific colum name you get the list by name:
$dataObject->getListByName('LastName') // means: get the list of all values from a column named last_name

If you want to show an entry of a specific row column you can write
something like this:
$dataObject->getLastName(2) // means: get the last name from row 3

If your resource includes columns from foreign tables then
you can address a column by following notation, too:

SELECT * FROM md_employees
LEFT JOIN md_departments ON md_departments.department_id=md_employees.department_id

As you can see the table name is attached to the column after the of separator.
'FirstNameOfMdEmployees' is called the perspective name of the model perspective.
Why? The data result set gives you a new perspective onto the data cloud.
Here it is a simple left join. By this notation you must not give attention
to the column names. If there is more then one column of the same name, the
table name (relation name) will be attached to the column (attribute name).
Overwriting of columns in array will be avoided automatically.
It is nearly the same as a full qualified name. But it is a php name, first.
I could tell you more about my data model theory, but that shall be enough.

Further dynamically generated methods:



$dataObject->getFieldTypes(); // list of the field types
$dataObject->getFieldPositions(); // list of the positions of the fields
$dataObject->getFieldFlags(); // list of the field flags
$dataObject->getFieldLengths(); // list of the field lengths
$dataObject->getTableNames(); // list of the table names for fields
$dataObject->getPerspectives(); // perspective names list

Additional Field Flag Functionality:
MySQL delivers following field flags if your MySQL version suports it:

QDataObject provides this by "type" prefix methods. If you want to check a field
for its field type, you can call a flag by following methods:

QDataObject provides this by "is" prefix methods. If you want to check a field
for its field flags, you can call a flag by following methods:
(All is-prefixed field flag methods return a boolean statement.)

QDataObject provides this by "of" prefix methods. If you want to check the type of
a field then call following methods:
(All of-prefixed field flag methods return a boolean statement.)
and so on (It is works on the real mysql field type names.)

QDataObject provides this by "len" prefix methods. If you want to check the length of
a field then call it the following way:

$object -> {prefix}{name-of-field-camelcased)()



Due to the fact, not the lack, that generic or better meta programming
does not show the provided methods directly, you can use the showMethods
method for getting an image of what is going on.

Showing provided methods:
echo $dataObject->showMethods();


This class is very compact, it has only some 300 lines of code. But it is mighty, because
it handles columns generically. You need not to write the getter and setter methods
manually. They are already there.
Someone who knows how to handle it, understands immediately what can be done with
this data object. I do know.
For more information send a message to info at phpclasses dot org.