I have 4 classes, each with their own database tables:
- GlobalObject
- Image
- Project
- Page
GlobalObject has 3 properties
- global_object_id
- added_by
- datetime_added
Image, Project and Page have many different fields, they ALL have the following though:
- id
- global_object_id (Foreign key)
At the moment, my class structure has Images, Projects and Pages as subclasses of the GlobalObject class, this allows the 3 subclasses access to the variables that are required of them, datetime_added etc.
How should I set the properties using PHP and MySQL? At the moment, ALL of the fields (including those in the global_object table) are in each section's table (except global_object_id which cannot exist without the new table - and is why I need to do this), So i request the data from the Image table for example, which includes all the properties in the parent class and is set using parent::set_by_row($database_args), and $this->set_by_row($database_args);
At the moment I do the following (Using Image as an example):
class Image extends GlobalObject
{
$id;
$title;
function set_by_id($id)
{
// Select Q from Image table
$this->set_by_row($db_result);
}
function set_by_row($args)
{
parent::set_by_row($args);
// Set class properties
}
}
To reiterate: I want to be able to do the following:
$image = new Image()
$image->set_by_global_object_id(23);
And the image be set, including everything in the parent class (which is stored in a separate table)
Please ask away if any of that is unclear.