Weedpacket brings up a very good point. I actually do have a database class that I use frequently. And the purpose of it was to be able to use postgres (haven't written that side of it yet) and MySQL while using the same PHP code. All I will have to do is create a variable (better known as a property in classes) that I can reference within the class to decide whether to do internal or hidden work within my class for PostGreSQL or MySQL. The beauty if that my PHP code where I call it will never now the difference 'cause my methods are uniform.
You bring up a good point that people can get carried away with classes. Obviously, with my example, It's just as easy to have an include statement to drop in somtimes 😃 However, if you are building something where you anticipate using repetitive functions, etc. classes can facilitate your coding significantly.
Here's a sample of code that I have written today using a couple of different classes. It won't make too much sense, but hopefully I have implemented my class methods in a way that, symantically, makes the code easy to read and demonstrate the convenience that coding with classes can provide:
$forms->validateInput("txtClientName", REXP_EMPTY, "Client Name cannot be blank.");
$forms->validateInput("txtAddress", REXP_EMPTY, "Address cannot be blank.");
$forms->validateInput("txtCity", REXP_EMPTY, "City cannot be blank.");
$forms->validateInput("txtPhone", REXP_EMPTY, "Phone cannot be blank.");
$forms->validateInput("txtFirstName", REXP_EMPTY, "Contact Firstname cannot be blank.");
$forms->validateInput("txtLastName", REXP_EMPTY, "Contact Lastname cannot be blank.");
$forms->validateInput("txtEmail", REXP_EMAIL, "Contact Email is blank or invalid.");
if (!$forms->hasFormErrors()) {
/*** INSERT CLIENT ***/
$pm->data->add_insert("Client", trim($_POST['txtClientName']));
$pm->data->add_insert("RenewalMonth", trim($_POST['mnuRenewalMonth']));
$pm->data->add_insert("SalesPerson", trim($_POST['mnuSalesperson']));
if ($_POST['chkAssocParent'] == "yes")
$pm->data->add_insert("ParentID", $_POST['mnuParentClient']);
if ($_POST['chkBillParent'] == "yes")
$pm->data->add_insert("BillParent", 1);
$clientId = $pm->data->exec_insert("Clients");
/*** INSERT CLIENT ADDRESS ***/
$pm->data->add_insert("ClientID", $clientId);
$pm->data->add_insert("AddressType", "billing");
$pm->data->add_insert("Address", trim($_POST['txtAddress']));
$pm->data->add_insert("Address2", trim($_POST['txtAddress2']));
$pm->data->add_insert("City", trim($_POST['txtCity']));
$pm->data->add_insert("State", trim($_POST['mnuState']));
$pm->data->add_insert("Postal", trim($_POST['txtPostalCode']));
$pm->data->add_insert("Country", trim($_POST['mnuCountry']));
$pm->data->exec_insert("ClientAddresses");
/*** INSERT CLIENT PHONE ***/
$pm->data->add_insert("ClientID", $clientId);
$pm->data->add_insert("PhoneNumber", trim($_POST['txtPhone']));
$pm->data->add_insert("PhoneType", "business");
$pm->data->exec_insert("ClientPhones");
/*** INSERT CLIENT FAX ***/
$pm->data->add_insert("ClientID", $clientId);
$pm->data->add_insert("PhoneNumber", trim($_POST['txtFax']));
$pm->data->add_insert("PhoneType", "fax");
$pm->data->exec_insert("ClientPhones");
/*** INSERT PERSON ***/
$pm->data->add_insert("FirstName", trim($_POST['txtFirstName']));
$pm->data->add_insert("LastName", trim($_POST['txtLastName']));
$personId = $pm->data->exec_insert("People");
/*** INSERT PERSON EMAIL***/
$pm->data->add_insert("PersonID", $personId);
$pm->data->add_insert("Email", trim($_POST['txtEmail']));
$pm->data->exec_insert("PersonEmails");
/*** MAKE PERSON-CLIENT ASSOCIATION ***/
$pm->data->add_insert("ClientID", $clientId);
$pm->data->add_insert("PersonID", $personId);
$pm->data->exec_insert("ClientPersons");
/*** FEEDBACK OR REDIRECT ***/
if (!headers_sent()) {
header("Location: /clientslist.php");
exit();
} else {
$feedBack = "Client added successfully.";
}
}