Hi All,
After years of basic 'linear' PhP programming, where I defined most standard actions in functions, but no classes were used, I now have a project which I am using as a testbed for OOP.
To start with, I got a database class from the web (MySQL Singleton Class to allow easy and clean access to common mysql commands by ricocheting; http://www.ricocheting.com/). This is used to perform all sorts of database actions.
Now I am creating a class 'data_array' which I will use to store and manipulate all data that comes in arrays. in specific, I would like to extend this to a child class: 'label'. This will hold arrays with labels and ID values from lookup tables. Very usefull if you process large volumes of data, and you just want to get the ID values of your categorization labels for instance.
OK, enough about what I am building. The questions:
Am I correct in thinking that OOP main strong point compared to linear programming (But with all standard routines captured in functions) lays in the 'memory' of the objects; e.g., you can easily store and retreive information in an organized way?
When I need to insert a label, because the label is unknown, I need to call the database class to perform the insert operation. Would this fit within good OOP practice? That you create a database object within a class definition?
So, would this be ok to do:
Class Label extends data_array {
Public function InsertLabel($name)
{
$db = Database::obtain($db_host, $db_user, $db_password, $db_name);
$db->connect();
$recordid = $db->updateinsert(_LABEL_T_, $name, 'l_value');
$db->close();
// set label to array
}
If not: How would one add a label to the database here?