This paper mainly introduces the thinkphp framework to realize the user information query update and deletion function, combined with the example form analysis of thinkphp Framework database configuration, control and template call implementation of information query, update, delete and other functions related operation skills, need friends can refer to, hope to help everyone.
A code
1. Configuration files
<?phpreturn Array ( ' app_debug ' = False, //Off debug mode ' db_type ' = ' mysql ', //database type ' Db_ HOST ' + ' localhost ', //database server address ' db_name ' = ' db_database30 ', //Database name ' Db_user ' + ' root ' , //database user name ' db_pwd ' + ' root ', //Database Password ' db_port ' = ' 3306 ', //Database Port ' db_ PREFIX ' = ' think_ ', //data table prefix);? >
2. Entry file
<?phpdefine (' Think_path ', ' ... /thinkphp '); Define the thinkphp frame path (relative to the entry file) define (' App_name ', ' APP '); Define the project name define (' App_path ', './app '); Define the project path require (Think_path. /thinkphp.php "); Load Frame Entry file App::run (); Instantiate a site application instance?>
3. Controller files
<?phpheader ("content-type:text/html; Charset=utf-8 "); Set page encoding format class Indexaction extends action{public Function index () {$db = M (' User '); Instantiate the model class, the parameter data table name, which does not contain a prefix $select = $db->order (' id desc ')->limit ()->select (); $this->assign (' select ', $select); The template variable is assigned a value $this->display (); Specify template page} public Function Update () {$db = M (' User '); Instantiate the model class, parameter data table name, without prefix $select = $db->where (' id= '. $_get[' id ')->select (); $this->assign (' select ', $select); Template variable Assignment $this->display (update); Specify the template page if (isset ($_post[' id ')) {$data [' user '] = $_post[' user ']; Assignment of the data object property to be modified $data [' pass '] = MD5 ($_post[' pass '); $data [' address '] = $_post[' address ']; $result = $db->where (' id= '. $_post[' id ')->save ($data); Save modified data according to conditions if ($result) {$this->redirect (' Index/index ', ' ', 2, ' Data Update succeeded '); Page redirection}}} public function Delete () {$db = M (' UsEr '); Instantiate the model class, parameter data table name, without prefix $result = $db->where (' id= '. $_get[' id ')->delete (); Delete user data with ID 5 if ($result) {$this->redirect (' Index/index ', ' ', 2, ' data deletion succeeded '); Page redirection}}}?>
4, template file one
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
5. template file Two
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Two running results