WebSite-PHP Framework PHP
Multi langues
Mode Ajax simple
Aucun HTML, aucun JavaScript
URL rewrinting
Envoi d'email
Sitemap - RSS - Web service
Télécharger le Framework WebSite-PHP maintenant
 


Loading
 


Tutorial : Insert / Update / 
Delete customer

Tutoriels

>

Tutoriel Database

>

Tutorial : Insert / Update / Delete customer


Database-01: Tutoriel du composants Database du FrameWork PHP WebSite-PHP.

Tutorial : Insert / Update / Delete customer:

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

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


Retourner aux tutoriels du composants Database



Code source

Code source


Fichier: /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 Object();
        
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 Object($this->render"<br/>");
    }
}
?>


Retourner aux tutoriels du composants 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-2016 WebSite-PHP Framework PHP
Accueil Documentation Télécharger Quick start Tutoriels Wiki Issue Tracker