【php】3、学生管理系统-查看用户
<?php include_once 'stuService.class.php'; session_start(); $name = $_SESSION['student_name']; if($name == "") { header("Location: stu_login.php?error=1"); exit(); } $pagesize = 20; $pagenow = 1; $pagecount = 0; $service = new stuservice(); $pagecount = $service->getpagecount($pagesize); if(!empty($_GET['pagenow'])) { $pagenow=$_GET['pagenow']; } $stulist = $service->getstulist($pagesize, $pagenow); ?> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>学生成绩管理系统</title>
stuservice类
<?php //这个是对数据库中表student的操作 include_once 'mysql.class.php'; include_once 'student.class.php'; include_once 'confing.php'; class stuservice { //根据用户名和密码,查看个数 public function checkstunum($name, $password) { $mysql = new mysql(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $num=0; $sql = "select count(*) from student where stu_name = '".$name."' and stu_password = '".$password."'"; //执行命令 $res = $mysql->execute_dql($sql); $row=mysqli_fetch_row($res); if($row) { $num=$row[0]; } mysqli_free_result($res); $mysql->close_connect(); return $num; } //根据每页的大小,和当前的页面查询出所有的学生 public function getstulist($pagesize,$pagenow) { $mysql = new mysql(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $sql="select * from student limit ".($pagenow-1)*$pagesize.",$pagesize"; $res=$mysql->execute_dql($sql); $arr=array(); $i=0; while($row = mysqli_fetch_assoc($res)) { $arr[$i++]=$row; } mysqli_free_result($res); $mysql->close_connect(); return $arr; } //得到总页数 public function getpagecount($pagesize) { $mysql = new mysql(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $sql="select count(stu_id) from student"; $res=$mysql->execute_dql($sql); $i=0; $row = mysqli_fetch_row($res); if($row) { $rowcount=$row[0]; } $pagecount=ceil($rowcount/$pagesize); //返回不小于 value 的下一个整数,value 如果有小数部分则进一位。 mysqli_free_result($res); $mysql->close_connect(); return $pagecount; } //根据学生姓名得到相应数据 public function getstu($name) { $stu = new student(); $mysql = new mysql(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $sql="select * from student where stu_name='".$name."'"; $res=$mysql->execute_dql($sql); if($row = mysqli_fetch_assoc($res)) { $stu->setStu_id($row['stu_id']); $stu->setStu_name($row['stu_name']); $stu->setStu_password($row['stu_password']); } mysqli_free_result($res); $mysql->close_connect(); return $stu; } //根据id号获取user public function getstubyid($id) { $stu = new student(); $mysql = new mysql(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $sql="select * from student where stu_id='".$id."'"; $res=$mysql->execute_dql($sql); if($row = mysqli_fetch_assoc($res)) { $stu->setStu_id($row['stu_id']); $stu->setStu_name($row['stu_name']); $stu->setStu_password($row['stu_password']); } mysqli_free_result($res); $mysql->close_connect(); return $stu; } //根据得到的对象修改数据库中的值 public function update(student $stu) { $mysql = new mysql(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $sql="update student set stu_name='".$stu->getStu_name()."',stu_password='".$stu->getStu_password()."' where stu_id=".$stu->getStu_id(); $b = $mysql->execute_dml($sql);// if($b == 1)// {// return true;// } return $b; } //删除用户 public function delete(student $stu) { $mysql = new mysql(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $sql = "delete from student where stu_id=".$stu->getStu_id().";"; $b = $mysql->execute_dml($sql); return $b; } }?>
mysql类
<?php // include_once 'confing.php'; class mysql extends mysqli {// public $link;// public $db_host = DB_HOST;// public $db_user = DB_USER;// public $db_password = DB_PASSWORD;// public $db_name = DB_NAME; public function __construct($host, $user, $pass, $db) { parent::__construct($host, $user, $pass, $db); if (mysqli_connect_error()) { die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); }// $this->link = new mysqli($this->db_host, $this->db_user, $this->db_password, $this->db_name);// if(!$this->link){// die("连接失败".mysql_error());// } //mysql_select_db($this->dbname,$this->link); } //执行SQL语句得到结果集,查询语句 public function execute_dql($sql) { $res = $this->query($sql) or die(mysqli_error($this)); return $res; } //执行SQLdml语句插入,更新,删除 public function execute_dml($sql) { $b = $this->query($sql) or die(mysqli_error($this)); if(!$b) { return 0; } else { if($this->affected_rows > 0) //如果收影响的行数大于0 { return 1; //OK了 } else { return 2; //没有行收到影响 } } } //关闭连接 public function close_connect() { if(!empty($this)) $this->close(); } } ?>
student类
<?php class student { private $stu_id; private $stu_name; private $stu_password; /** * @return the $stu_id */ public function getStu_id() { return $this->stu_id; } /** * @return the $stu_name */ public function getStu_name() { return $this->stu_name; } /** * @return the $stu_password */ public function getStu_password() { return $this->stu_password; } /** * @param field_type $stu_id */ public function setStu_id($stu_id) { $this->stu_id = $stu_id; } /** * @param field_type $stu_name */ public function setStu_name($stu_name) { $this->stu_name = $stu_name; } /** * @param field_type $stu_password */ public function setStu_password($stu_password) { $this->stu_password = $stu_password; } } ?>
config.php配置数据库
<?php //用define定义常量 //连接服务器 define('DB_HOST', 'localhost'); //连接数据库的账号 define('DB_USER', 'root'); //连接数据库的密码 define('DB_PASSWORD', 'xiaofeng2015'); //连接数据库的名字 define('DB_NAME', 'studentmanage'); //?>
预览:

thesecrettokeepingaphp-poweredwebsterunningsmootlyunderheavyloadinvolvesseveralkeystrategies:1)emform opcodecoduceSciptionexecutiontime、2)aatabasequerycachingwithiThing withiThistolessendavasoload、

コードをより明確かつ維持しやすくするため、依存関係が関心(DI)に注意する必要があります。 1)DIは、クラスを切り離すことにより、よりモジュール化されます。2)テストとコードの柔軟性の利便性を向上させ、3)DIコンテナを使用して複雑な依存関係を管理しますが、パフォーマンスの影響と円形の依存関係に注意してください。

はい、最適化されたAphPossibleandessention.1)CachingingusapCutoredatedAtabaseload.2)最適化、効率的なQueries、およびConnectionPooling.3)EnhcodeCodewithBultinctions、Avoididingglobalbariables、およびUsingopcodeching

keyStrategIestsoSificlyvoostphpappliceperformanceare:1)useopcodecachinglikeToreexecutiontime、2)最適化abaseの相互作用とプロペラインデックス、3)3)構成

aphpDependencyInjectionContaineriSATOULTAINATINAGECLASSDEPTINCIES、強化測定性、テスト可能性、および維持可能性。

SELECT DEPENTENCINGINOFCENT(DI)大規模なアプリケーションの場合、ServicElocatorは小さなプロジェクトまたはプロトタイプに適しています。 1)DIは、コンストラクターインジェクションを通じてコードのテスト可能性とモジュール性を改善します。 2)ServiceLocatorは、センター登録を通じてサービスを取得します。これは便利ですが、コードカップリングの増加につながる可能性があります。

phpapplicationscanbeoptimizedforspeedandEfficiencyby:1)enabingopcacheinphp.ini、2)PreparedStatementswithpordatabasequeriesを使用して、3)LoopswithArray_filterandarray_mapfordataprocessing、4)の構成ngincasaSearverseproxy、5)

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

SAP NetWeaver Server Adapter for Eclipse
Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

Safe Exam Browser
Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。

WebStorm Mac版
便利なJavaScript開発ツール
