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???
object oriented PHP help
Moderator: General Moderators
Re: object oriented PHP help
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.
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();
}
}