Controller code:
Demo2Controller.class.php
<?phpnamespace Home\controller; UseThink\controller; UseThink\model;classDemo2controllerextendsController {//Insert Operation Public functiontest1 () {$Model=NewModel (); $sql= "INSERT into city (CITYNAME,PROVINCE,CITYDESC) VALUES (' Shijiazhuang ', ' Hebei province ', ' Hebei province ')"; $Model->execute ($sql); EchoThe Insert Action; } //Delete Operation Public functiontest2 () {$Model=NewModel (); $sql= "Delete from city where cityname= ' Shijiazhuang '"; $Model->execute ($sql); Echo"Delete Action"; } //Update Operation Public functiontest3 () {$Model=NewModel (); $sql= "Update City set citydesc= ' capital of Hebei province ' where Cityname= ' Shijiazhuang '"; $Model->execute ($sql); Echo"Update Action"; } //Select Operation Public functiontest4 () {$Model=NewModel (); $sql= "SELECT * from City ORDER by ID ASC"; $list=$Model->query ($sql); $this->assign (' list ',$list); $this-display (); }}
The view page for the Select operation:
Test4.html
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "UTF-8"><title>Test3</title></Head><Body><Tablewidth= "100%"Border= "1"cellspacing= "0"cellpadding= "0"> <TR> <TD>Serial number</TD> <TD>City</TD> <TD>Capital</TD> <TD>Describe</TD> </TR> <foreachname= "List"Item= "Item"Key= "Index"> <TR> <TD>{$index +1}</TD> <TD>{$item. CityName}</TD> <TD>{$item. Province}</TD> <TD>{$item. Citydesc}</TD> </TR> </foreach></Table></Body></HTML>
Execute native SQL with thinkphp