Php+ci MySQL for additional pruning and checking

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.