10.2. Building a Comments Class

Separating your commenting system separate from the rest of your blog makes it easier to maintain and extend in the future; you'll leverage the object-oriented approach you learned about in Chapter 8 to implement this feature.

Begin by creating a new file that will contain the class. Call this file comments.inc.php, and store it in the inc folder in the simple_blog project (full path: /xampp/htdocs/simple_blog/inc/comments.inc.php).

Once you create the file, you need to declare the class and a constructor for it. This class must be able to read and write from the database, so you need to include the database information stored in db.inc.php.

Your class needs a property to hold the database variable. Your class ...

Get PHP for Absolute Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.