[nycphp-talk] Object Oriented Question

evan heller evan.heller at
Fri Jun 7 15:20:37 EDT 2002


I tend to make everything I do now into classes
partly because I'm sick and tired of reinventing
the wheel everytime I make a new site.

Anyhow, for example, I'm building the site: and everything is a

So for example I have a basic database class that 
knows how to handle a mysql, odbc or a oracle
and returns all results as an 2 dimensional
associative array
but when using it all I have to say is such: 
$db = New DB($username,$database,$databasetype);
$somesql = "select username,password from users";
$results = $db->Select($somesql);
if (is_array($results)) {
	for ($i=0;$i<count($results);$i++) {
		print $results[$i]["username"];

Now I know that's more code than just going to the
however I can now feed that database object to
other objects
or better yet, not have to worry about
or whatever depending on the database types, as
the database class
 will handle all of that, plus its easier for
others to work with
if they would like to help add to your site.

On my site I also have bookreviews which is really
a class called
Bookreviews (a collection of books) with a
subclass called Book 
(which is a generic book class) which has a
subclass called Database.
As you go higher up the class chain, it becomes
more and more 
abstracted. So the final page may only access a
book, or a 
collection of books based on a search or a
category. It becomes
very flexible and the best part is I can easily
reuse it
later on in another program with minimal or (if
its well done) no
modification at all.

A good example is that a friend of mine was able
to adapt my book
review class system to his site with no changes at
all but the types
of books and the database were different 
(from comics books to real books).


Evan Heller     
evan.heller at

More information about the talk mailing list