? ? ? ? 本文主要講述如何通過PHP+HTML簡單實現BBS論壇和發帖/回帖的功能,這是提取我們php項目的部分內容。主要內容包括:
? ? ? 1.[通過JavaScript和Iframe實現局部布局界面](http://blog.csdn.net/eastmount/article/details/43848585)
? ? ? 2.PHP如何定義類實現訪問數據庫功能
? ? ? 3.實現簡單的BBS論壇和發帖/回帖功能
? ? ? 由于這個項目是十個人在寒假完成,所以采用了SAE搭建在線的后臺數據庫,其他人在通過Apache本地設計網頁、訪問數據庫的方法實現,相當于簡單的BS三端訪問。
? ? ? 源碼下載地址:[http://download.csdn.net/detail/eastmount/8501443](http://download.csdn.net/detail/eastmount/8501443)
? ? ? 訪問[http://localhost:8080/testphp/index.php](http://localhost:8080/testphp/index.php)效果如下圖所示:



### 一. 首頁布局搭建
? ? ? 首先是搭建首頁的布局,主要布局分為head、main_left和main_right。其中右邊顯示部分采用的是iframe實現的局部顯示,而左邊采用JavaScript實現點擊隱藏和顯示功能。其中index.php首頁代碼如下:
~~~
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>《分布式系統》精品課程學習</title>
<link href="css/mycss.css" type="text/css" rel="stylesheet"/>
<style type="text/css">
/* 這個鏈接改變顏色 */
a.one:link {color: #ff0000}
a.one:visited {color: #0000ff}
a.one:hover {color: #ffcc00}
</style>
</head>
<body>
<!-- 布局頂部登錄狀態 -->
<div id="main">
<TABLE cellSpacing=0 cellPadding=0 width="100%"
background="images/header_bg.gif" border=0>
<!--頭部圖片-->
<TR height=80>
<TD width=260>
<IMG height=80 src="images/logo.png" width=260>
</TD>
<TD style="FONT-SIZE: 12px; FONT-WEIGHT: bold; COLOR: #000;
PADDING-TOP: 20px; PADDING-RIGHT: 20px" align=right>
您還未登錄!?|
<A class="one" href="login.php" >登錄</A>|
<A class="one" href="register_student.php" >學生注冊</A>|
<A class="one" href="register_teacher.php" >教師注冊</A>
</TD>
</TR>
</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TR bgColor=#1c5db6 height=4>
<TD></TD></TR>
</TABLE>
<br />
<!-- 布局中部 -->
<div id="middle">
<!-- 布局中部右邊 -->
<div id="index_right">
<iframe height="100%" width="100%" border="0" frameborder="0"
src="main_right.php" name="rightFrame" id="rightFrame" title="rightFrame">
</iframe>
</div>
<!-- 布局中部左邊 -->
<div id="index_left">
<?php
include('main_left.php');
?>
</div>
</div>
~~~
? ? ? 這里的CSS代碼布局調用css文件中的mycss.css實現:
~~~
html, body {
height: '100%';
width: '100%';
}
/*頭部布局*/
#main{
margin-left:200px;
width:950px;
}
/*中部布局*/
#middle{
width:950px;
height:500px;
background-color:#b6effa;
}
/*中部左邊*/
#index_left{
float:left;
margin-top:10px;
margin-left:10px;
width:180px;
height:480px;
}
/*中部右邊*/
#index_right{
float:right;
margin-top:10px;
margin-right:20px;
width:720px;
height:480px;
border-style:double;
}
/*中部右邊*/
#logout_middle{
float:right;
margin-top:100px;
margin-right:220px;
width:500px;
height:300px;
border-style:double;
background-color:#ffffff;
}
~~~
? ? ? 在Iframe中主要的代碼是<iframe?src="main_right.php" name="rightFrame" id="rightFrame">,調用時“<A href="main_right3-1.php"?target="rightFrame">BBS論壇</A>”聲明target為rightFrame即可。同時隱藏顯示設置style.display為block或none。
? ? ? 其中main_left.php代碼如下,此時即可實現上面的布局。
~~~
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<LINK href="css/admin.css" type="text/css" rel="stylesheet">
<SCRIPT language=javascript>
function expand(el) {
childObj = document.getElementById("child" + el);
if (childObj.style.display == 'none') {
childObj.style.display = 'block';
} else {
childObj.style.display = 'none';
}
return;
}
</SCRIPT>
</HEAD>
<BODY>
<TABLE height="100%" cellSpacing=0 cellPadding=0 width=170
background=images/menu_bg.jpg border=0 align=left>
<TR>
<TD vAlign=top align=middle>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TR>
<TD height=10></TD></TR>
</TABLE>
<!-- 第一選項 -->
<TABLE cellSpacing=0 cellPadding=0 width=150 border=0>
<TR height=30>
<TD style="PADDING-LEFT: 20px; FONT-SIZE: 15px" background=images/menu_bt.jpg>
<A class=menuParent onclick=expand(1)
href="javascript:void(0);">課程首頁</A></TD></TR>
<TR height=4>
<TD></TD></TR>
</TABLE>
<TABLE id=child1 style="DISPLAY: none" cellSpacing=0 cellPadding=0
width=150 border=0>
<TR height=20>
<TD align=middle width=30><IMG height=9
src="images/menu_icon.gif" width=9></TD>
<TD><A href="main_right1-1.php"
target="rightFrame">首頁介紹</A></TD></TR>
<TR height=4>
<TD colSpan=2></TD></TR>
</TABLE>
<!-- 第二選項 -->
<TABLE cellSpacing=0 cellPadding=0 width=150 border=0>
<TR height=30>
<TD style="PADDING-LEFT: 20px; FONT-SIZE: 15px" background=images/menu_bt.jpg>
<A class=menuParent onclick=expand(2)
href="javascript:void(0);">課程概況</A></TD></TR>
<TR height=4>
<TD></TD></TR>
</TABLE>
<TABLE id=child2 style="DISPLAY: none" cellSpacing=0 cellPadding=0
width=150 border=0>
<TR height=20>
<TD align=middle width=30><IMG height=9
src="images/menu_icon.gif" width=9></TD>
<TD><A href="guest/main_right2-1.php"
target="rightFrame">課程簡介</A></TD></TR>
<TR height=20>
<TD align=middle width=30><IMG height=9
src="images/menu_icon.gif" width=9></TD>
<TD><A href="guest/main_right2-2.php"
target="rightFrame">教師團隊</A></TD></TR>
<TR height=20>
<TD align=middle width=30><IMG height=9
src="images/menu_icon.gif" width=9></TD>
<TD><A href="guest/main_right2-3.php"
target="rightFrame">教學條件</A></TD></TR>
<TR height=4>
<TD colSpan=2></TD></TR>
</TABLE>
<!-- 第三選項 -->
<TABLE cellSpacing=0 cellPadding=0 width=150 border=0>
<TR height=30>
<TD style="PADDING-LEFT: 20px; FONT-SIZE: 15px" background=images/menu_bt.jpg>
<A class=menuParent onclick=expand(3)
href="javascript:void(0);">互動交流</A></TD></TR>
<TR height=4>
<TD></TD></TR>
</TABLE>
<TABLE id=child3 style="DISPLAY: block" cellSpacing=0 cellPadding=0
width=150 border=0>
<TR height=20>
<TD align=middle width=30><IMG height=9
src="images/menu_icon.gif" width=9></TD>
<TD><A href="main_right3-1.php"
target="rightFrame">BBS論壇</A></TD></TR>
<TR height=20>
<TD align=middle width=30><IMG height=9
src="images/menu_icon.gif" width=9></TD>
<TD><A href="main_right3-2.php"
target="rightFrame">通知公告</A></TD></TR>
<TR height=4>
<TD colSpan=2></TD></TR>
</TABLE>
</BODY>
</HTML>
~~~
? ? ? 顯示的效果如下:

### 二. 實現BBS論壇及回復
? ? ? 論壇主要通過自定義類database文件夾下Httppost.php實現,其中main_right3-1.php是顯示所有BBS論壇帖子的主題,而main_right3-1-content.php是對應帖子的內容,包括回復內容等。
? ? ? 其中main_right3-1.php的代碼如下:
~~~
<?php
header("Content-Type: text/html; charset=utf-8");
//注意:include一個php文件不能重復,要遞歸檢查是否重復引用
include ("../database/httppost.php");
?>
<!-- 需要注意在Html中“..”表示回到上一級目錄 而css與main_right3-1.php同級目錄 -->
<link rel="stylesheet" href="css/main.css" type="text/css" />
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
<TR height=28>
<TD >當前位置: BBS論壇</TD>
<TD align=right><A href="main_right.php" class="one"> 返回 </A></TD>
</TR>
<TR>
<TD bgColor=#b1ceef height=1 colspan="2"></TD></TR>
<TR height=10>
<TD background=images/shadow_bg.jpg colspan="2"></TD></TR>
</TABLE>
<div class="middle">
<div class="wrap">
<div class="wrap_left">
<div class="wenda-head">
<a href="#" class="quealltab onactive" >最新</a>
<a href="#" class="quealltab " >熱門</a>
<a href="#" class="quealltab " >等待回復</a>
</div>
<?php
//查詢貼
$hgi=new HttpPostInf();
$result=$hgi->doquery('2',"select * from BBS_Post;");
//解析json
$dj=json_decode($result,true);
$jcount=count($dj);
for($i=0; $i<$jcount; $i++){
?>
<div class="wenda-list">
<div class="headslider">
<img src='images/bbs3.jpg' class="wenda_list_head" width='40' height='40' />
<a href="" title="name" class="wenda-nickname"><?php echo $dj[$i]['BP_Pid']; ?></a>
</div>
<div class="qaslider">
<ul>
<li><img src="images/bbs1.jpg" class="icon"/><a
href="main_right3-1-content.php?bbsid=<?php echo $dj[$i]['BP_Pid']; ?>"
class="wendatitle"><?php echo $dj[$i]['BP_Ptitle']; ?></a></li>
<li><img src="images/bbs2.png" class="icon2"/><span class="replydet">發帖身份:
<?php
if($dj[$i]['BP_Ptype']==0) echo "教師";
if($dj[$i]['BP_Ptype']==1) echo "學生";
?>
??|??發帖人編號:
<?php echo $dj[$i]['BP_Puserid']; ?></span></li>
<li><span class="time">提問時間:<?php echo $dj[$i]['BP_Ptime']; ?></span>
</ul>
</div><!--qaslider-->
</div><!--wenda-list-->
<?php
//結束循環
}
?>
</div><!--wrap-->
</div><!--wrap_right-->
</div><!--middle-->
<TABLE cellSpacing=0 cellPadding=2 width="95%" align=center border=0 >
<TR height=20>
<TD></TD>
</TR>
</TABLE>
~~~
? ? ? 這里需要指出HTML代碼"../database/httppost.php"中".."表示返回上一級目錄,該代碼的目錄如下圖所示,源代碼放在Apache中htdocs文件夾中。

? ? ? 其中main_right3-1-content.php代碼如下:
~~~
<?php
header("Content-Type: text/html; charset=utf-8");
include ("../database/human.php");
session_start();
?>
<link rel="stylesheet" href="css/main.css" type="text/css" />
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
<TR height=28>
<TD background=images/title_bg1.jpg>當前位置: BBS論壇</TD>
<TD align=right><A href="main_right6-1.php" class="one"> 返回 </A></TD>
</TR>
<TR>
<TD bgColor=#b1ceef height=1 colspan="2"></TD></TR>
<TR height=10>
<TD background=images/shadow_bg.jpg colspan="2"></TD></TR>
</TABLE>
<!-- PHP數據庫中獲取內容 -->
<?php
//查詢BBS
$hgi=new HttpPostInf();
$result=$hgi->doquery('2',"select * from BBS_Post where BP_Pid='".$_GET['bbsid']."';");
//解析json
$dj=json_decode($result,true);
$jcount=count($dj);
for($i=0; $i<$jcount; $i++){
$_SESSION['bbsid']=$dj[$i]['BP_Pid'];
?>
<div class="middle">
<div class="wrap">
<div class="wrap_left">
<div class="wenda-head">
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0 bgcolor="blue">
<TR height=10>
<TD></TD></TR>
<TR height=22>
<TD style="PADDING-LEFT: 10px; FONT-WEIGHT: bold; COLOR: #ffffff"
align=left>[貼]?<?php echo $dj[$i]['BP_Ptitle']; ?></TD></TR>
<TR height=10>
<TD></TD></TR>
</TABLE>
</div>
<!-- 樓主內容 -->
<TABLE cellSpacing=0 cellPadding=0 width="95%" align=center border=0>
<tr>
<td valign="top"><div align="middle" width=150><BR /><BR /><img
src='images/tx.jpg' width='60' height='60' />
<BR /><BR />樓主 1# <BR />
<?php echo $dj[$i]['BP_Puserid']; ?>
<BR />身份
<?php
if($dj[$i]['BP_Ptype']==0) echo "教師";
if($dj[$i]['BP_Ptype']==1) echo "學生";
?><BR /><?php echo $dj[$i]['BP_Ptime']; ?></div></td>
<!-- 多行文本輸入控件 disabled="disabled"不可編輯 -->
<td ><textarea rows="15" type="text" width="400px" style="resize:none;font-size:16px;"
maxlength="2000" name="content" cols="60" disabled="disabled"><?php echo $dj[$i]['BP_Cont']; ?></textarea></td>
</tr>
<TR height=4>
<TD colspan="3"></TD>
</TR>
<tr>
<td colspan="2"><hr width="100%" size="2" color="#FF0000"></td>
</tr>
</TABLE>
<!--上面的php中while循環并沒有結束,還有右括號-->
<?php
}
//查詢BBS
$hgi=new HttpPostInf();
$result=$hgi->doquery('2',"select * from BBS_Reply where BR_Pid='".$_GET['bbsid']."';");
//解析json
$dj=json_decode($result,true);
$jcount=count($dj);
for($i=0; $i<$jcount; $i++){
?>
<!-- 樓層回復內容 -->
<TABLE cellSpacing=0 cellPadding=0 width="95%" align=center border=0>
<tr>
<td valign="top"><div align="middle" width=150><BR /><BR />
<img src='images/tx.jpg' width='60' height='60' />
<BR /><BR />樓層 <?php $_SESSION['bbshfid']=time(); echo $i+2;?># <BR />
<?php echo $dj[$i]['BR_Ruserid']; ?>
<BR />身份
<?php
if($dj[$i]['BR_Rtype']==0) echo "教師";
if($dj[$i]['BR_Rtype']==1) echo "學生";
?>
<BR /><?php echo $dj[$i]['BR_Ptime']; ?>
<BR />回復樓層<?php echo $dj[$i]['BR_Pfloor']; ?>#</div></td>
<!-- 多行文本輸入控件 disabled="disabled"不可編輯 -->
<td ><textarea rows="15" type="text" width="400px" style="resize:none;font-size:16px;"
maxlength="2000" name="content" cols="60" disabled="disabled"><?php echo $dj[$i]['BR_Cont']; ?></textarea></td>
</tr>
<TR height=4>
<TD colspan="3">
</TD>
</TR>
<tr>
<td colspan="2"><hr width="100%" size="2" color="#FF0000"></td>
</tr>
</TABLE>
<?php
}
?>
<!-- 回復內容 -->
<form id="form1" name="form1" method="post" action="main_right3-1-content.php">
<TABLE cellSpacing=0 cellPadding=0 width="95%" align=center border=0>
<tr>
<td colspan="2">??回復樓層
<input type="text" name="lc" id="lc" value="" style=width:150pt; maxlength="50"/>
</td>
</tr>
<tr>
<td valign="top"><div align="middle" width=150>
<BR /><BR />???回復???<BR /></div></td>
<!-- 多行文本輸入控件 disabled="disabled"不可編輯 -->
<td ><textarea rows="10" type="text" width="400px" style="resize:none;font-size:16px;" maxlength="2000"
name="bbscontent" cols="60" ></textarea></td>
</tr>
<tr>
<td colspan="2" align="middle">
<input type="submit" style='font-size:22px' name="Submit" value="提交回復"/>
</td>
</tr>
<TR height=4><TD colspan="3"></TD></TR>
<tr>
<td colspan="2"><hr width="100%" size="2" color="#FF0000"></td>
</tr>
</TABLE>
</form>
</div><!--wrap-->
</div><!--wrap_right-->
</div><!--middle-->
<TABLE cellSpacing=0 cellPadding=2 width="95%" align=center border=0>
<TR height=20>
<TD></TD></TR>
</TABLE>
<!-- 提交當前頁面POST數據庫表單處理 -->
<?php
if (!empty($_POST['bbscontent']))
{
if($_SESSION['radio']==1) $a=1; //學生
if($_SESSION['radio']==2) $a=0; //老師
//SQL更新
$sql = "INSERT INTO BBS_Reply (BR_Rid,BR_Pid,BR_Ruserid,BR_Rtype,BR_Ptime,BR_Pfloor,BR_Cont) VALUES (";
$sql .= "'".$_SESSION['bbshfid']."',";
$sql .= "'".$_SESSION['bbsid']."',";
$sql .= "'".$_SESSION['number']."',";
$sql .= "'".$a."',";
$sql .= "'".date('Y-m-d')."',";
$sql .= "'".$_POST['lc']."',";
$sql .= "'".$_POST['bbscontent']."'";
$sql .= ");";
//更新信息
//echo $sql;
$hgi=new HttpPostInf();
$result=$hgi->doquery('1',$sql);
//echo "<script>alert('恭喜你修改成功!');</script>";
header('Location:main_right3-1.php');
}
?>
~~~
? ? ? 發帖回復顯示效果如下圖所示:


? ? ? 發帖的代碼就不貼出來了,可以查看源代碼。寫到此處可能你會疑惑數據庫訪問部分的內容,下面進行簡單講解吧!
### 三. PHP定義類及成員函數
? ? ? 在PHP中我們通常課程學習時完成的網站都是基于面向過程的方法,從而忽略了它的面向對象知識,我顯然也犯了這樣的錯誤。
? ? ? PS:由于該項目是《面向對象分析與開發》課程作業,所以需要用面向對象的知識去分析和實現。突然有一天我發現PHP以前用的都是HTML和PHP布局后臺實現的,沒用用到類、封裝、繼承的知識,但查閱相關資料后發現它都是有這些東西的。
? ? ? 后來在實現這個項目過程中我們定義了不同的類(感謝PU哥),這里僅僅舉例數據庫方面和Human類。
~~~
<?php
header("Content-Type: text/html; charset=utf-8");
class HttpPostInf{
function __construct(){ //無參構造函數
}
function doquery($type , $sql){ //網路通信函數
$data = array ('sqlType' => $type , 'sqlExe' => $sql);
$data = http_build_query($data);
$opts = array ('http' => array ('method' => 'POST','header'=>
"Content-type: application/x-www-form-urlencoded\r\n" ."Content-Length: "
. strlen($data) . "\r\n",'content' => $data));
$context = stream_context_create($opts);
$html = file_get_contents('http://courseweb.sinaapp.com/courseweb.php', false, $context);
return $html;
}
}
?>
~~~
? ? ? 同時定義Human類,而繼承該類的Student和Teacher是兩種身份的登陸用戶。其中構造函數、實例化都已經在成員函數中寫好。
~~~
<?php
header("Content-Type: text/html; charset=utf-8");
include_once("httppost.php");
//人類,擁有教師和學生的共同屬性和方法
class Human{
private $hid; //唯一編號
private $pwd; //密碼
private $name; //名字
private $sex; //性別
private $email; //郵箱
function __construct(){ //無參構造函數
}
//靜態驗證函數
static function id_vf($id,$spwd,$type){ //類靜態方法 type=1為學生,2為老師
$hpi=new HttpPostInf();
if($type==1)
{
$result=$hpi->doquery('2',"select * from Student_Info where Sinf_id='".$id."';");
if($result =='error' || $result=='null'){ //返回無值
return -1; //沒有用戶,返回0
}
else{
$dj=json_decode($result,true);
$jcount=count($dj);
for($i=0; $i<$jcount; $i++){
//只有一個密碼
$right_pwd=$dj[$i]['SInf_Pwd']; //學生登錄密碼
}
if($spwd == $right_pwd) return 1; //驗證成功,可以登陸
else return 0;//密碼錯誤
}
}
else if($type==2)
{
$result=$hpi->doquery('2',"select * from Teacher_Info where TI_id='".$id."';");
if($result =='error' || $result=='null'){ //返回無值
return -1; //沒有用戶,返回0
}
else{
$dj=json_decode($result,true);
$jcount=count($dj);
for($i=0; $i<$jcount; $i++){
//只有一個密碼
$right_pwd=$dj[$i]['TI_Pwd']; //學生登錄密碼
}
if($spwd==$right_pwd) return 1; //驗證成功,可以登陸
else return 0;//密碼錯誤
}
}
}
}
class Student extends Human{
private $bir; //出生日期
private $maj; //專業
private $eym; //入學年份
private $score; //得分
function __construct($sid){ //1參構造函數
$this->hid=$sid;
$stu=new HttpPostInf();
$result=$stu->doquery('2',"select * from Student_Info where Sinf_ID='".$sid."';");
//echo 'result:'.$result;
//解析json
$dj=json_decode($result,true);
$jcount=count($dj);
for($i=0; $i<$jcount; $i++){
//只返回1個,所以只取一個即可,jcount=1
$this->bir=$dj[$i]['SInf_Bir'];
$this->maj=$dj[$i]['SInf_Maj'];
$this->eym=$dj[$i]['SInf_Eym'];
$this->score=$dj[$i]['SInf_Score'];
//或者寫:$score=$dj->Sinf_Bir;
$this->pwd=$dj[$i]['SInf_Pwd'];
$this->name=$dj[$i]['SInf_Name'];
$this->sex=$dj[$i]['SInf_Sex'];
$this->email=$dj[$i]['SInf_Email'];
}
}
function getname(){return $this->name;}
function getsex(){return $this->sex;}
function getemail(){return $this->email;}
function getpwd(){return $this->pwd;}
function getbir(){return $this->bir;}
function getmaj(){return $this->maj;}
function geteym(){return $this->eym;}
function getscore(){return $this->score;}
}
class Teacher extends Human{
private $ptitle; //職稱
private $res; //成果
private $award; //獲獎
function __construct($tid){ //1參構造函數
$this->hid=$tid;
$stu=new HttpPostInf();
$result=$stu->doquery('2',"select * from Teacher_Info where TI_ID='".$tid."';");
//echo 'result:'.$result;
//解析json
$dj=json_decode($result,true);
$jcount=count($dj);
for($i=0; $i<$jcount; $i++){
//只返回1個,所以只取一個即可,jcount=1
$this->ptitle=$dj[$i]['TI_Ptitle'];
$this->res=$dj[$i]['TI_Res'];
$this->award=$dj[$i]['TI_Award'];
//或者寫:$score=$dj->Sinf_Bir;
$this->pwd=$dj[$i]['TI_Pwd'];
$this->name=$dj[$i]['TI_Name'];
$this->sex=$dj[$i]['TI_Sex'];
$this->email=$dj[$i]['TI_Email'];
}
}
function getname(){return $this->name;}
function getsex(){return $this->sex;}
function getemail(){return $this->email;}
function getpwd(){return $this->pwd;}
function getptitle(){return $this->ptitle;}
function getres(){return $this->res;}
function getaward(){return $this->award;}
}
?>
~~~
? ? ? 再調用上面定義的類HttpPostInf和Human,實現訪問數據庫的簡單代碼如下所示:
? ? ? <?php
? ? ? ? ? ? ??//查詢貼
? ? ? ? ? ? ? $hgi=new HttpPostInf();
? ? ? ? ? ? ??$result=$hgi->doquery('2',"select * from BBS_Post;");//SQL語句
? ? ? ? ? ? ??//解析json
? ? ? ? ? ? ??$dj=json_decode($result,true);
? ? ? ? ? ? ??$jcount=count($dj);
? ? ? ? ? ? ??for($i=0; $i<$jcount; $i++) {? ?
? ? ? ? ? ? ? ? ? ? ? echo $dj[$i]['BP_Pid'];
? ? ? ? ? ? ??}
? ? ???>
? ? ? 而當用戶登錄后會使用Session記錄用戶的id,然后通過類實例化即可實現獲取該用戶的所有信息,簡單的代碼如下:
? ? ? $h1=new Student('2220140598');
? ? ? echo $h1->getname(); echo '<br>';
? ? ? echo $h1->getsex(); echo '<br>';
? ? ? echo $h1->getemail(); echo '<br>';
? ? ? 最后希望文章對大家有所幫助,尤其發現PHP方面搭建的文章比較少!相對多的文章是PHP關于某個細節處理,同時更希望大家學習下PHP類相關的知識。總感覺自己寫博客有些問題,但自己說不出來,希望大家提出不足之處!該代碼數據庫是布局在SAE上的,所以直接運行可以出現上面所有圖形的效果。
? ? (By:Eastmount 2015-3-14 下午4點 ?[http://blog.csdn.net/eastmount/](http://blog.csdn.net/eastmount/))