object oriented PHP help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
arjun
Forum Newbie
Posts: 4
Joined: Tue Aug 11, 2009 10:37 am

object oriented PHP help

Post by arjun »

I have finished basic tutorial of w3schools in php.now i am doing Object oriented PHP.
can anybody give me a sample program like registration forms using object oriented php and mysql???
dejvos
Forum Contributor
Posts: 122
Joined: Tue Mar 10, 2009 8:40 am

Re: object oriented PHP help

Post by dejvos »

I think this should help. this is a class to insert address of rss feed into a database. Files PEAR.php, DB.php and HTML/QuickForm.php are packages which you can download on http://pear.php.net.

I hope it's helpful.

Code: Select all

 
require_once 'DB.php';
require_once 'PEAR.php';
require_once 'HTML/QuickForm.php';
 
class rss_handler {
    const DB_TABLE_NAME = 'rss_handler_feed';
 
    public $db;
 
    private $messages = "";
 
    public function rss_handler ($dsn){
        $this->db =& DB::connect($dsn);
        if(DB::isError($this->db)) return PEAR::raiseError('[ERROR rss_handler001:]'.$this->db->getMessage,1);
        $tables =& $this->db->getCol("SHOW TABLES LIKE '".rss_handler::DB_TABLE_NAME."';");
        if(DB::isError($tables)) return PEAR::raiseError('[ERROR rss_handler002:]'.$tables->getMessage,2);
 
        if(empty($tables)) {
            $form = new HTML_QuickForm('make_table');
            $rend =& $form->defaultRenderer();
            $rend->setElementTemplate('<div><label>{label}</label>{element}</div>');
            $rend->setElementTemplate('<div class="rss_notice">{header}</div>','notice');
            $rend->setFormTemplate("<form {attributes}>\n<div class=\"form\">{content}</div></form>");
            $form->addElement('header','notice','Nepoda?ilo se nalézt tabulku "'.rss_handler::DB_TABLE_NAME.'". P?ejete si jí vytvo?it?');
            $form->addElement('submit','submit_table','Vytvo?it tabulku');
            $this->messages .= $form->toHtml();
        };
    }
 
    public function getInsertFeedForm(){
        $form = new HTML_QuickForm('inser_feed');
        $rend =& $form->defaultRenderer();
 
        return $form->toHtml();
    }
 
    public function renderInsertFeedForm(){
        echo $this->messages;
        echo $this->getInsertFeedForm();
    }
}
 
 
Post Reply