溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

使用PHP怎么實(shí)現(xiàn)數(shù)據(jù)庫的增刪查改功能

發(fā)布時間:2021-05-22 16:22:25 來源:億速云 閱讀:167 作者:Leah 欄目:開發(fā)技術(shù)

這篇文章將為大家詳細(xì)講解有關(guān)使用PHP怎么實(shí)現(xiàn)數(shù)據(jù)庫的增刪查改功能,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

TP_3.2.2/Application/Home/Controller/StuController.class.php

<?php 

namespace Home\Controller; 
use Think\Controller; 
class StuController extends Controller 
{ 
 public function StuShow(){ 
  $this->display("school/stu"); 
 } 
 public function getdata(){ 
  $Studata = M('stu'); 
  $data['id']=''; 
  $data['name']=I('get.name'); 
  $data['age']=I('get.age'); 
  $data['num']=I('get.num'); 
  $data['address']=I('get.add'); 
  $Studata->add($data); 
  $this->success("正在。。。",U('Stu/showdata')); 
 } 
 public function showdata() 
 { 
  $Studata = M('stu'); 
  $data=$Studata->select(); 
  $this->assign('info',$data); 
  $this->display('school/showdata'); 
 } 
 public function del(){ 
  $id = I('get.id'); 
  $Studata = M('stu'); 
  $bool = $Studata->where(['id'=>$id])->delete(); 
  if($bool){ 
   echo 1; 
  }else{ 
   echo 0; 
  } 
 } 
 public function updata() 
 { 
  $id = I('get.id'); 
  $Studata = M('stu'); 
  $data = $Studata->where(['id'=>$id])->find(); 
  $this->assign('data',$data); 
  $this->display("school/upshowdata"); 
 } 
 public function updatadeal() 
 { 
  $Studata = M('stu'); 
  $id = I('get.id'); 
  $data['name']=I('get.name'); 
  $data['age']=I('get.age'); 
  $data['num']=I('get.num'); 
  $data['address']=I('get.add'); 
  $bool = $Studata->where(['id'=>$id])->save($data); 
  if($bool){ 
   $this->showdata(); 
  }else{ 
   echo 0; 
  } 
 } 
}

TP_3.2.2/Application/Home/View/school/showdata.html

<!DOCTYPE html> 
<html lang="en"> 
<head> 
 <meta charset="UTF-8"> 
 <title>數(shù)據(jù)展示界面</title> 
</head> 
<body id="content"> 
<center> 
 <h3>學(xué)生信息展示</h3> 
<table border="1"> 
 <th>編號</th> 
 <th>姓名</th> 
 <th>年齡</th> 
 <th>學(xué)號</th> 
 <th>籍貫</th> 
 <th>操作</th> 
 <th>操作</th> 
<foreach name="info" item="vo" > 
 <tr> 
  <td>{$vo['id']}</td> 
  <td>{$vo['name']}</td> 
  <td>{$vo['age']}</td> 
  <td>{$vo['num']}</td> 
  <td>{$vo['address']}</td> 
  <td><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" class="del" where="{$vo['id']}">刪除</a></td> 
   <td><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" class="up" where="{$vo['id']}">修改</a></td> 
 </tr> 
</foreach> 
</table> 
</center> 
</body> 
</html> 
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script> 
<script> 
 $('.del').click(function () { 
  var where = $(this).attr('where'); 
  $.ajax({ 
   type: "get", 
   url: "{:U('Stu/del')}?id="+where, 
   success: function(msg){ 
    if(msg==1){ 
     alert('刪除成功'); 
     location.href('showdata'); 
    }else { 
     alert('刪除失敗'); 
    } 
   } 
  }); 
 }) 
 $('.up').click(function () { 
  var where = $(this).attr('where'); 
  location.href('updata?id='+where); 
  // $.ajax({ 
  //  type: "get", 
  //  url: "{:U('Stu/updata')}?id="+where, 
  //  success: function(msg){ 
  //   $('#content').html(msg); 
  //  } 
  // }); 
 }) 
</script>

TP_3.2.2/Application/Home/View/school/stu.html

<!doctype html> 
<html lang="en"> 
<head> 
 <meta charset="UTF-8"> 
 <meta name="viewport" 
   content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> 
 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 
 <title> 學(xué)號注冊查詢系統(tǒng) </title> 
</head> 
<body> 
<form action="{:U('Stu/getdata')}" method="get"> 
 <br> 
 名字: <input type="text" name="name"> 
 <br> 
 年齡: <input type="text" name="age"> 
 <br> 
 學(xué)號:<input type="text" name="num"> 
 <br> 
 籍貫:<input type="text" name="add"> 
 <br> 
 <input type="submit" value="提交"> 
 <br> 
</form> 
</body> 
</html>

TP_3.2.2/Application/Home/View/school/stu.html

<!doctype html> 
<html lang="en"> 
<head> 
 <meta charset="UTF-8"> 
 <meta name="viewport" 
   content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> 
 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 
 <title> 學(xué)號注冊查詢系統(tǒng) </title> 
</head> 
<body> 
<form action="{:U('Stu/updatadeal')}" method="get"> 
 <input type="hidden" value="{$data['id']}" name="id"> 
 <br> 
 名字: <input type="text" name="name" value="{$data['name']}"> 
 <br> 
 年齡: <input type="text" name="age" value="{$data['age']}"> 
 <br> 
 學(xué)號:<input type="text" name="num" value="{$data['num']}"> 
 <br> 
 籍貫:<input type="text" name="add" value="{$data['address']}"> 
 <br> 
 <input type="submit" value="提交"> 
 <br> 
</form> 
</body> 
</html>

php有什么特點(diǎn)

1、執(zhí)行速度快。2、具有很好的開放性和可擴(kuò)展性。3、PHP支持多種主流與非主流的數(shù)據(jù)庫。4、面向?qū)ο缶幊蹋篜HP提供了類和對象。5、版本更新速度快。6、具有豐富的功能。7、可伸縮性。8、功能全面,包括圖形處理、編碼與解碼、壓縮文件處理、xml解析等。

關(guān)于使用PHP怎么實(shí)現(xiàn)數(shù)據(jù)庫的增刪查改功能就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI