PHP
  Home arrow PHP arrow Page 3 - Defining the Core Structure of a PHP Blogger
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Defining the Core Structure of a PHP Blogger
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 11
    2006-11-21


    Table of Contents:
  • Defining the Core Structure of a PHP Blogger
  • Defining the blogger's core structure
  • Defining the insertBlog() method
  • Defining the updateBlog() method
  • Defining the deleteBlog() method

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Defining the Core Structure of a PHP Blogger - Defining the insertBlog() method
    ( Page 3 of 5 )

    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:

    CREATE TABLE blogs (
                id INTERGER(4) UNSIGNED AUTO_INCREMENT, PRIMARY KEY,
                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(){
    $title=$this->blogData['title'];
                $author=$this->blogData['author'];
                $content=$this->blogData['content'];
                $this->mysql->query("INSERT INTO blogs (id,author,title,content,date)
    VALUES (NULL,'$author','$title','$content',TIMESTAMP(10))");
                header('Location:'.$_SERVER['PHP_SELF']);                            
    }

    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
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT