WebSite-PHP Framework PHP
Multi language
Simple Ajax mode
No HTML, no JavaScript
URL rewriting
Mail sending
Sitemap - RSS - Web service
Download WebSite-PHP FrameWork now
 


Loading
 


Tutorial : Insert / Update / 
Delete customer

Tutorials

>

Tutorial Database

>

Tutorial : Insert / Update / Delete customer


Database-01: Tutorial of the composant Database of the PHP FrameWork WebSite-PHP.

Tutorial : Insert / Update / Delete customer:

Customer :
customer_id : 2
name : Toto
address : 5th, street principal

customer_id : 2
name : Toto
address : 13th, street second


Go back to tutorial of the componant Database



Source code

Source code


File: /pages/tutorials/database/database-01.php

<?php
class Database01 extends Page {
    public function 
InitializeComponent() {
        
parent::$PAGE_TITLE "Tutorial : Insert / Update / 
                                Delete customer"
;
        
        
$this->render = new WSPObject();
        
DataBase::getInstance()->beginTransaction();
        
        
// Insert
        
$cutomer = new CustomerObj();
        
$cutomer->setName("Toto");
        
$cutomer->setAddress("5th, street principal");
        
$cutomer->save();
        
        
$this->render->add(new Label(
                
ucfirst(CustomerDbTable::TABLE_NAME), true), 
                
" :<br/>");
        
$this->render->add(CustomerDbTable::FIELD_CUSTOMER_ID":",
                        
$cutomer->getCustomerId(), "<br/>");
        
$this->render->add(CustomerDbTable::FIELD_NAME":"
                        
$cutomer->getName(), "<br/>");
        
$this->render->add(CustomerDbTable::FIELD_ADDRESS":"
                        
$cutomer->getAddress(), "<br/><br/>");
        
        
// Update
        
$cutomer_upd = new CustomerObj();
        
$cutomer_upd->load($cutomer->getCustomerId());
        
$cutomer_upd->setAddress("13th, street second");
        
$cutomer_upd->save();
        
        
$this->render->add(CustomerDbTable::FIELD_CUSTOMER_ID":",
                        
$cutomer_upd->getCustomerId(), "<br/>");
        
$this->render->add(CustomerDbTable::FIELD_NAME":"
                        
$cutomer_upd->getName(), "<br/>");
        
$this->render->add(CustomerDbTable::FIELD_ADDRESS":"
                        
$cutomer_upd->getAddress());
        
        
// Delete
        
$cutomer_upd = new CustomerObj();
        
$cutomer_upd->load($cutomer->getCustomerId());
        
$cutomer_upd->delete();
        
        
DataBase::getInstance()->commitTransaction();
        
        
$this->render = new WSPObject($this->render"<br/>");
    }
}
?>


Go back to tutorial of the componant Database


Tables

Tables


drop table if exists customer;

/*==============================================================*/
/* table: customer                                              */
/*==============================================================*/
create table customer
(
   customer_id          int not null  auto_increment,
   name                 varchar(50),
   address              varchar(100),
   primary key (customer_id)
) engine = innodb;


Share

 


Copyright © 2009-2024 WebSite-PHP Framework PHP
Home Documentation Download Quick start Tutorials Wiki Issue Tracker