<?php
class DataField
{
function TYPE_STRING()
{
return 1;
}
function TYPE_NUMERIC()
{
return 2;
}
var $db_type = null;
var $is_primary_key = null;
var $value = null;
function DataField($col_type, $is_pk)
{
$this->db_type = $col_type;
$this->is_primary_key = $is_pk;
}
}
?>
(see lines 7 and 8 in the Hippo code above, and line 7 in ArmedHippo). Declaring them this way subjects
them to the same scope and inheritance rules as other methods.
BusinessBase::addField()
(called by Hippo and ArmedHippo) adds a field to$records
:
<?php
function addField( $db_col_name, $field )
{
$this->record[$db_col_name] = $field;
}
?>
BusinessBase::load()
looks like this:
<?php
function load($id)
{
$this->find_id_field();
$conn = mysql_connect('localhost', 'hippo_user', 'hippo_user');
mysql_select_db('hippos');
$query = 'select * from '.$this->table_name.' where '.$this->_id_field." = $id";
$fetched_record = mysql_fetch_assoc( mysql_query($query) );
foreach ($this->record as $col_name=>$field)
$this->record[$col_name]->value = $fetched_record[$col_name];
application_utility_tasks();
}
?>
BusinessBase::load()
calls find_id_field()
in line 3 to locate the primary key field, and store its name in
$this->_id_field
for later use.The method then opens the database (line 4), builds a SELECT query (line 7), and executes it
(line 9). Lines 11-13 move the data into
$record
, where it can be retrieved with a statementlike this from Hippo: