The CI of PHP is a framework of the MVC pattern, this article is through the PHP+CI to the MySQL database to carry on the enhancement and deletion check.
0. First create a database and data table on MySQL database side
1 Create Databasetest;2 Usetest;3 CreateTablesUser(4Idint(Ten) not NULLAuto_increment,5Namevarchar( -) not NULL,6Ageint(Ten) not NULL,7 Primary Key(ID)8);
View Code
1. Modifying the database configuration file (application/config/database.php)
2. Append models Processing module (application/models/user_model.php)
1<?PHP2 3 classUser_modelextendsCi_model4 {5 6 function__construct ()7 {8Parent::__construct ();9 //Connect to the databaseTen $this->load->database (); One } A - functionUser_insert ($arr) - { the $this->db->insert (' User ',$arr); - } - - functionUser_update ($id,$arr) + { - $this->db->where (' id ',$id); + $this->db->update (' User ',$arr); A } at - functionUser_delete ($id) - { - $this->db->where (' id ',$id); - $this->db->delete (' user '); - } in - functionUser_select ($id) to { + $this->db->where (' id ',$id); - $this->db->select (' * ')); the $query=$this->db->get (' user '); * return $query-result (); $ }Panax Notoginseng}
View Code
3. Add Controller processing module (application/controllers/user.php)
1<?PHP2 3 classUserextendsCi_controller4 {5 Public functionInsert ()6 {7 $this->load->model (' User_model ');8 $arr=Array(' name ' = ' aaa ', ' age ' =>16);9 $this->user_model->user_insert ($arr);Ten } One A Public functionUpdate () - { - $this->load->model (' User_model '); the $arr=Array(' id ' =>2, ' name ' = ' bbb ', ' age ' =>23); - $this->user_model->user_update (2,$arr); - } - + Public functionDelete$id) - { + $this->load->model (' User_model '); A $this->user_model->user_delete ($id); at } - - Public functionSelect () - { - $this->load->model (' User_model '); - $arr=$this->user_model->user_select (1); in Print_r($arr); - } to}
View Code
4. The database can be added and hacked through the URL.
Php+ci MySQL for additional pruning and checking