I'm fairly new to PHP/MySQL, but have successfully made a couple small dynamic sites. I'm trying to understand the power of classes and figure out the best approach for future projects.
Let's use the basic example of a book inventory, with each book having a unique ISBN number, a title, and author. As I understand classes, I can think of this as an object/class:
class book {
var $isbn;
var $title;
var $author;
}
I've also seen a number of examples of using classes for database management/interaction, such as:
class mysql {
var $host;
var $db;
//.... other variables
function connect_db($host, $username, $password) {
$conn = mysql_connect($this->host, $this->username, $this->password);
}
}
I'm trying to figure out: when people talk about object-oriented, are they referring to "real-world" representations of the problem, in which case I think of the books as objects in the app, or do I need to look at the application's objects, such as the database, browser, etc.?? It seems like a good db class would handle all database interaction, so what's the point of the other classes other than for templating or function libraries? I mean, if I have the mysql class, what's the point of another class for the books? All the articles I've seen on OO say that it's great for managing sites, so I thought I'd look into it.