Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

DotGeek:
Database Abstraction and OOP
Jan 09, 2004 @ 13:16:52

New from DotGeek.org this morning is a tutorial that will be of great interest for those out there working with OOP and databases.

In Practical use of classes: DB abstraction, OO website, the author seeks to teach abstraction in a PHP class through a simple database example. Using classes you can not only make your code easier to reuse in the future, but it makes a nice little "package" that you can move around from site to site. The author gives a procedural example of how most coders new to PHP would connect to the database, and follows it up with an OOP example that not only looks cleaner, but can also be much more flexible.

The class that he defines has functions for connecting/disconnecting, selecting the DB, and making the query. One nice thing about this approach is the ability to make the class "abstracted" for whatever kind of database you're using (meaning it would work for both MySQL and PostgreSQL). He continues on, showing other features that this database class can do, including various ways to output the results of your query.

tagged:

Link:


Trending Topics: