Home arrow PHP arrow Page 3 - Defining the Core Structure of a PHP Blogger

Defining the insertBlog() method - PHP

In the first part of this three-part series, we'll examine the basic outlines of creating a blog application with PHP 5. If you're currently working with PHP 4, this program can be adapted to that version of the language.

  1. Defining the Core Structure of a PHP Blogger
  2. Defining the blogger's core structure
  3. Defining the insertBlog() method
  4. Defining the updateBlog() method
  5. Defining the deleteBlog() method
By: Alejandro Gervasio
Rating: starstarstarstarstar / 11
November 21, 2006

print this article



Before I proceed to define the signature of the method responsible for adding new entries to the blog application, let me first explain briefly how I'm going to create the corresponding database schema with MySQL. In simple terms, I'm going to use only one table, called "blogs" (yep, my own creativity sometimes blows me away), which will contain the following fields: "ID," "title," "author," "content" and finally a column named "date."

As you'll imagine, each one of the referenced fields will house the ID of a particular blog entry, its title and date, the name of the author who posted it and lastly the content in question. Definitely, after having at hand the description of all the corresponding fields that comprise the "blogs" database table, creating its structure is reduced to something as simple as this:

            author VARCHAR(45) NOT NULL,
            title VARCHAR(45) NOT NULL,
            content LONGTEXT NOT NULL,
            date TIMESTAMP

All right, now that you know how the previously-defined "blogs" database table has been properly defined, have a look at the following method that belongs to the "BlogProcessor" class. It is called "insertBlog()" and is tasked with adding new entries to the referenced table:

// insert new blog
private function insertBlog(){
            $this->mysql->query("INSERT INTO blogs (id,author,title,content,date)
VALUES (NULL,'$author','$title','$content',TIMESTAMP(10))");

As you'll certainly agree, the above method is quite straightforward. It merely inserts a new blog entry into the respective "blogs" database table, and uses the values entered on the corresponding web form to perform the insertion process. Finally, the method finishes its execution by redirecting the user to the same web document where all the blogs will eventually be displayed. Simple and efficient, right?

At this stage, and assuming that the method you saw before isn't difficult to understand, let's move forward and see together how to define another method included with the "BlogProcessor" class, which will be useful for updating a particular blog entry.

As usual, to see how this will be done, please click on the link below and keep reading.

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: