Field | Type | Notes |
id | integer | Primary key Auto increment |
name | text | |
num_mount_points | integer |
Hippo::load()
and Hippo::save()
into
ArmedHippo
, and add the num_mount_points field.
<?php
//ArmedHippo methods
function load($id) {
$this->id = $id;
$conn = mysql_connect('localhost', 'hippo_user', 'hippo_user');
mysql_select_db('hippos');
$result = mysql_query("select name,
num_mount_points from hippos where id=$id");
$this->name = mysql_result($result, 0, 'name');
$this->num_mount_points = mysql_result($result, 0, 'num_mount_points');
application_utility_tasks();
}
function save()
{
$conn = mysql_connect('localhost', 'hippo_user', 'hippo_user');
mysql_select_db('hippos');
if ( is_null($this->id) )
{
//New record
$query = "insert into hippos (name, num_mount_points)
values ('".$this->name."', ".
$this->num_mount_points.")";
mysql_query($query);
$this->id = mysql_insert_id();
}
else
{
//Update existing record
$query = "update hippos set name='".$this->name."',
num_mount_points=".$this->num_mount_points."
where id=".$this->id;
mysql_query($query);
}
application_utility_tasks();
}
?>
record, and gets the id number allocated to it by MySQL on line 21. If id is not null,
save() uses it an a primary key value in an SQL UPDATE statement (line 25).
also need to change
ArmedHippo::load()
and ArmedHippo::save()
.If we add StealthHippo, we’ll introduce more code that needs to be changed as Hippo changes.
Further, all versions of the
load()
and save()
methods call
application_utility_tasks()
separately. If we need to change the call, the code must beupdated in every place.