new Record - jcobban/Genealogy GitHub Wiki
new Record($dbrow, $newTable)
Up: class Record
New instances of Record are created using the constructor function. This constructor is most commonly called from the constructors of classes derived from Record, and from class RecordSet. The parameters for this constructor are:
parameter | description |
---|---|
$dbrow | An associative array object. When this constructor is invoked from a derived class this contains a row containing all fields in the table record. All of the field names in this array must be in lower case. This is stored in $this->row. This can also be a partial array containing only enough field values to identify a single record from the database. When identifying a record in this way the case of the field names is unimportant. |
$newTable | The name of the table from which the above array object was retrieved. To ensure that the functionality works on Linux based servers this name must be in mixed case and must be an index of the array $primeKey. This is stored in $this->table. |
In almost all situations the Record constructor, and also the constructors for all classes derived from Record, completes normally. In particular if there is no matching record for the set of keys supplied the constructors complete but fill the record with default values based upon the parameters. If there are errors in the parameters which mean that the constructed instance cannot be stored in the database the constructor still completes but records the reasons for the failure in $record->msg
. If an unrecoverable problem occurs in this constructor, it throws an Exception but the only situations where this would happen indicate a logic error in the application, for example a failure to establish a connection to the database server. Exceptions tend to result in messages being displayed to users that users will not understand and are not able to act on. The include files for the derived classes should be viewed to see examples of the use of this constructor.
When implementing a derived class avoid invoking the constructor of any other class beside the parent, as this can create an infinite recursion. Delay creating any dependent record until that record is actually required to obtain information to be returned to the caller.
Example:
$record = new Record($result, 'tblTC');
creates a Record based upon a complete record read from the database by an SQL SELECT * FROM tblTC
WHERE ...
Example:
$record = new Record(array('idtc' => $idtc), 'tblTC');
creates an instance of Record which contains the contents of a record from table 'tblTC' as identified by the key field 'idtc' with value $idtc. This should only be used for tables which do not have a derived class encapsulation. Since those tables are generally treated as collections, the most convenient way to access them is through the class RecordSet. For example you can get all of the contents of this table as a set by:
$set = new RecordSet('tblTC');
Next: $record->getInfo()