Curd basic operation of thinkphp, Thinkphpcurd
Speaking of Curd, understand a bit of SQL people know, is to delete and change, do business system, often inseparable from this curd, recently also just touch thinkphp,thinkphp flexibility is more than native PHP easy to use more, below I will briefly introduce my learning experience.
Learn thinkphp to MySQL operation, first you have to have MySQL, and then PHP run environment.
Wamp can help you solve the problem of configuration, about Wamp information, Baidu can.
The following is a brief introduction to the thinkphp of the process of adding and deleting.
First, create the database, named T_user.
The code is:
DROP TABLE IF EXISTS ' T_user '; CREATE TABLE ' t_user ' (' userid ' int (one) not NULL, ' username ' varchar) DEFAULT NULL, ' usersex ' varchar (6 Default NULL, ' Userage ' int (6) default NULL, PRIMARY KEY (' userid ')) engine=innodb default Charset=utf8;
Create a project, named Thinkphp_text, to import the thinkphp core package.
Configure the index.php file.
Start the project and automatically generate the catalog. Such as:
The Add () operation about thinkphp.
Create an action file of index, name IndexController.class.php, write a function insertuser (), in the control layer, you want to get the value of the foreground.
/** * Add user Information * encoding time: 2015-05-28*/ Public functionInsertuser ($id,$name,$sex,$age){$this->DB (1, "DB_CONFIG1")->db (1);$condition=Array(//define the data to be added, put in an array, named $condition' UserID ' =$id, ' username ' =$name, ' usersex ' =$sex, ' userage ' =$age,);$addInfo=$this->DB (1, "DB_CONFIG1")->add ($condition);//Execute SQL statement, insertif($addInfo){Header("location:http://localhost/thinkphp_text/index.php"); }Echo $this->getlastsql ();//Adjust the trial, output SQL statementsreturn $addInfo; }/**
In the model layer, remember the naming method, in this configuration, named UserModel.class.php, corresponding to:
1 /**2 * Add user information3* Encoding time: 2015-05-284 */5 Publicfunction Insertuser ($id, $name, $sex, $age) {6$ This->DB (1,"DB_CONFIG1")->db (1);7$condition = Array (//define the data to be added, put in an array, named $condition8 'userid'=$id,9 'username'=$name,Ten 'Usersex'=$sex, One 'Userage'=$age, A ); -$addInfo = $ This->DB (1,"DB_CONFIG1")->add ($condition);//Execute SQL statement, insert - if($addInfo) { theHeader"location:http://localhost/thinkphp_text/index.php"); - } -echo $ This->getlastsql ();//Adjust the trial, output SQL statements - return$addInfo; +}
This is the core code of the add operation.
Specific code please go to the following link to download, see the comments in detail:
Http://pan.baidu.com/s/1hq7wfnm
http://www.bkjia.com/PHPjc/1007359.html www.bkjia.com true http://www.bkjia.com/PHPjc/1007359.html techarticle thinkphp Curd Basic operation, Thinkphpcurd said Curd, understand point SQL people know, is to delete and change to check, do business system, often inseparable from this curd, recently also just contact ...