|
Database-01: Tutorial der Komponente Database vom PHP FrameWork WebSite-PHP. Tutorial : Insert / Update /
Delete customer:
Customer : customer_id : 10 name : Toto address : 5th, street principal
customer_id : 10 name : Toto address : 13th, street second
|
Zurück zum Tutorial der Komponente Database
|
Datei: /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/>"); } } ?>
Zurück zum Tutorial der Komponente Database
|
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;
|
|
|
|
|