使用PHP面向?qū)ο蠹夹g(shù)網(wǎng)站系統(tǒng)_第1頁
使用PHP面向?qū)ο蠹夹g(shù)網(wǎng)站系統(tǒng)_第2頁
使用PHP面向?qū)ο蠹夹g(shù)網(wǎng)站系統(tǒng)_第3頁
使用PHP面向?qū)ο蠹夹g(shù)網(wǎng)站系統(tǒng)_第4頁
使用PHP面向?qū)ο蠹夹g(shù)網(wǎng)站系統(tǒng)_第5頁
已閱讀5頁,還剩66頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

使用PHP面向?qū)ο蠹夹g(shù)網(wǎng)站系統(tǒng)第一頁,共71頁。學(xué)習(xí)重點(diǎn)面向?qū)ο蟮腤eb整站系統(tǒng)的設(shè)計(jì)方法面向?qū)ο蟮腤eb整站系統(tǒng)的編程方法學(xué)習(xí)難點(diǎn)由系統(tǒng)功能分析確定系統(tǒng)邏輯結(jié)構(gòu),并表現(xiàn)為程序結(jié)構(gòu)由系統(tǒng)架構(gòu)設(shè)計(jì)確定數(shù)據(jù)實(shí)體類和數(shù)據(jù)操作類設(shè)計(jì)數(shù)據(jù)操作類的編程實(shí)現(xiàn)及其在頁面邏輯程序中的調(diào)用第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)第二頁,共71頁。9.1Web整站系統(tǒng)的規(guī)劃和設(shè)計(jì)1、Web整站系統(tǒng)的構(gòu)成

Web整站系統(tǒng)指的是大型綜合網(wǎng)站系統(tǒng),由主要功能模塊和其它輔助功能模塊組成。

主要功能模塊指的是網(wǎng)站的主營業(yè)務(wù)模塊,如門戶網(wǎng)站的主模塊是新聞發(fā)布系統(tǒng),購物網(wǎng)站的主模塊是購物系統(tǒng),社區(qū)交友網(wǎng)站的主模塊是留言板和聊天室系統(tǒng)等等。

輔助功能模塊指的是為主模塊提供信息發(fā)布管理、聯(lián)系/交流/反饋、管理等服務(wù)的子系統(tǒng),如文章管理、留言板、聊天室、會員管理、用戶管理系統(tǒng)等等。

小型Web系統(tǒng)的各個功能模塊一般在同一個系統(tǒng)內(nèi)實(shí)現(xiàn),大型Web系統(tǒng)的各個功能模塊往往由多個Web子系統(tǒng)組成,通過頁面變量和會話變量傳送的方法實(shí)現(xiàn)相互聯(lián)系。Web整站系統(tǒng)一般都提供一個統(tǒng)一入口,即網(wǎng)站主頁,在主頁上通過導(dǎo)航條展示并鏈接到各個子系統(tǒng),而主頁的主要部分是用于展示主要功能模塊的內(nèi)容。

為了使內(nèi)容的組織合理、有序,方便用戶瀏覽,主功能模塊一般還采用分類列表展示的模式;為了使最新內(nèi)容能夠展現(xiàn)在網(wǎng)站主頁,一般主頁的中間部分(最醒目的部分)用于顯示各個欄目的最新內(nèi)容列表。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)第三頁,共71頁。9.1Web整站系統(tǒng)的規(guī)劃和設(shè)計(jì)2、Web整站系統(tǒng)設(shè)計(jì)的一般方法Web整站系統(tǒng)包含眾多頁面,一般采用CSS+HTML頁面設(shè)計(jì)方法,將風(fēng)格較為統(tǒng)一的頁面樣式放在同一個CSS文件中,實(shí)現(xiàn)頁面和樣式分離,方便設(shè)計(jì)和修改。Web整站系統(tǒng)的Web界面部分都有普通用戶訪問的頁面程序和管理員用戶訪問的頁面程序兩大部分,一般都將普通用戶界面稱為前臺頁面程序,管理員界面稱為后臺頁面程序,將前臺頁面文件置于網(wǎng)站根目錄下,而將后臺頁面文件置于后臺目錄下,如有上傳文件,將其置于前臺目錄下,便于目錄權(quán)限控制。Web整站系統(tǒng)的頁面文件中都有多段重復(fù)代碼,一般將重復(fù)代碼編寫為函數(shù)或放在包含文件中,便于重復(fù)使用和修改。Web系統(tǒng)從程序功能上看,一般可分為界面顯示、業(yè)務(wù)邏輯處理和數(shù)據(jù)庫操作3部分,將這3部分分離實(shí)現(xiàn),按層調(diào)用,即實(shí)現(xiàn)了所謂的“三層Web結(jié)構(gòu)”,這樣的結(jié)構(gòu)便于界面、代碼分離和程序修改、重用。

如果將數(shù)據(jù)及其屬性、操作方法封裝在一段代碼中,在使用的時候根據(jù)需要傳遞參數(shù),調(diào)用方法,獲取返回值,就實(shí)現(xiàn)了面向?qū)ο蟮木幊?,這是現(xiàn)代程序設(shè)計(jì)的主流方法。

為了提高網(wǎng)站顯示介面配置的靈活性,一般采用各個子頁面程序調(diào)用的方式,并在調(diào)用時傳入各種參數(shù),以組合形成所需要的顯示頁面。各種參數(shù)一般保存在數(shù)據(jù)庫的系統(tǒng)配置表中。3、系統(tǒng)功能設(shè)計(jì)門戶網(wǎng)站就是一個實(shí)現(xiàn)文章管理、發(fā)布的系統(tǒng)。從用戶角度看,包括訪客(普通用戶)使用的功能和管理員用戶使用的功能。從內(nèi)容管理角度看,包括欄目管理、文章管理、用戶管理、系統(tǒng)信息管理等功能。從操作角度看,系統(tǒng)包括讀、寫、修改、刪除等功能。另外還包括一些個性化的功能,如分類顯示以及圖片、音頻、視頻等多媒體信息的管理和發(fā)布等。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)第四頁,共71頁。9.2項(xiàng)目-面向?qū)ο蟮拈T戶網(wǎng)站的設(shè)計(jì)1、頁面程序結(jié)構(gòu)設(shè)計(jì)第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)登錄login.php表單輸入驗(yàn)證check.php后臺主頁index.php顯示:欄目列表、操作菜單、欄目文章列表及文章操作按鈕發(fā)送通過添加文章頁面addarticle.php修改文章頁面modifyarticle.php刪除文章deletearticle.php刪除橫幅修改橫幅退出登錄程序logout.php銷毀session退出管理員添加欄目頁面addtopic.php修改欄目頁面modifytopic.php刪除欄目程序deletetopic.php添加欄目修改欄目刪除欄目添加橫幅更新文章視頻頁面modifyarticlepic.php更新橫幅圖片更新文章視頻頁面modifyarticlevid.php主頁index.php包含:頭部頁面top.php導(dǎo)航頁面nav.php文章標(biāo)題圖片頁面picppt.php分類列表頁面list_hot.php、list_location.php、links.php橫幅條頁面poster.php底部頁面bottom.php閱讀文章內(nèi)容read.php點(diǎn)擊文章標(biāo)題或標(biāo)題圖片分欄目文章列表topic.php點(diǎn)擊欄目導(dǎo)航訪客點(diǎn)擊橫幅圖片圖片放大頁面showpic.php點(diǎn)擊文章標(biāo)題點(diǎn)擊欄目設(shè)置取消熱點(diǎn)hotarticle.php審核文章statusarticle.php修改橫幅頁面modifyposter.php更新橫幅圖片頁面modifyposterpic.php刪除橫幅deleteposter.php取消標(biāo)題圖片canelarticlepic.php取消文章視頻cancelarticlevid.php添加橫幅頁面addposter.php修改鏈接頁面modifylink.php更新鏈接圖片頁面modifylinkpic.php刪除鏈接deletelink.php添加鏈接頁面addlink.php添加用戶adduser.php刪除用戶deleteuser.php設(shè)置用戶權(quán)限priviliegeuser.php用戶信息列表user.php修改自己密碼modifypwdself.php修改用戶密碼modifypwd.php刪除鏈接修改鏈接添加鏈接更新鏈接圖片友情鏈接列表addlink.php橫幅信息列表頁面addposter.php添加文章修改文章更新標(biāo)題圖片更新文章視頻刪除文章設(shè)置取消熱點(diǎn)審核文章取消標(biāo)題圖片取消文章視頻修改用戶密碼刪除用戶添加用戶設(shè)置用戶權(quán)限修改自己密碼數(shù)據(jù)庫備份dbackup.php數(shù)據(jù)庫恢復(fù)dbrestore.php數(shù)據(jù)庫下載dbdownload.php數(shù)據(jù)庫備份數(shù)據(jù)庫下載數(shù)據(jù)庫恢復(fù)點(diǎn)擊欄目第五頁,共71頁。9.2項(xiàng)目-面向?qū)ο蟮拈T戶網(wǎng)站的設(shè)計(jì)2、目錄結(jié)構(gòu)設(shè)計(jì)第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)login.phpindex.phplogout.phpindex.phpaddtopic.phpmodifytopic.phpdeletetopic.phpaddarticle.phpmodifyaticle.phpmodifyaticlepic.phpmodifyaticlevid.phpdeletearticle.phpcancelarticlepic.phpcancelarticlevid.phpstatusarticle.phphotarticle.phpposter.phpaddposter.phpmodifyposter.phpmodifyposterpic.phpdeleteposter.phplinks.phpaddlink.phpmodifylink.phpmodifylinkpic.phpdeletelink.phpuser.phpadduser.phpmodifyuser.phppriviliege.phpmodifypwd.phpmodifypwdself.phpsysinfo.php網(wǎng)站根目錄(news)CSS目錄admin目錄upload目錄images目錄ckeditor目錄ckfinder目錄index.phptop.phpbottom.phpnav.phppicppt.phplist_hot.phplist_location.phptopic.phpserach.phplinks.phpread.phpposter.phpshowpic.phpserach.phpresult.phpinclude目錄config.phpentity.phpdbaccess.phpdbhandle.php第六頁,共71頁。9.2項(xiàng)目-面向?qū)ο蟮拈T戶網(wǎng)站的設(shè)計(jì)3、數(shù)據(jù)庫設(shè)計(jì)數(shù)據(jù)庫名:newsmarty表topic表article第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)第七頁,共71頁。9.2項(xiàng)目-面向?qū)ο蟮拈T戶網(wǎng)站的設(shè)計(jì)3、數(shù)據(jù)庫設(shè)計(jì)數(shù)據(jù)庫名:newsmarty表user表links表poster第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)第八頁,共71頁。9.2項(xiàng)目-面向?qū)ο蟮拈T戶網(wǎng)站的設(shè)計(jì)3、數(shù)據(jù)庫設(shè)計(jì)數(shù)據(jù)庫名:newsmarty表sysinfo第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)第九頁,共71頁。9.2項(xiàng)目-面向?qū)ο蟮拈T戶網(wǎng)站的設(shè)計(jì)4、系統(tǒng)架構(gòu)設(shè)計(jì)

系統(tǒng)采用OOP方法實(shí)現(xiàn),通過上述的頁面邏輯進(jìn)行頁面顯示和交互操作處理,在進(jìn)行數(shù)據(jù)操作時,頁面程序調(diào)用數(shù)據(jù)操作程序(集中放在函數(shù)庫文件中),數(shù)據(jù)操作函數(shù)再調(diào)用數(shù)據(jù)庫操作類,由數(shù)據(jù)庫操作類進(jìn)行數(shù)據(jù)庫存取操作;程序之間的數(shù)據(jù)傳輸通過封裝的數(shù)據(jù)對象進(jìn)行;在一定程度上實(shí)現(xiàn)了顯示界面、數(shù)據(jù)處理操作和數(shù)據(jù)的分離。系統(tǒng)架構(gòu)如圖所示:第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)頁面顯示和交互程序前臺頁面程序(顯示邏輯、計(jì)數(shù)、獲?。┖笈_頁面程序(顯示邏輯、計(jì)數(shù)、獲取、添加、修改、刪除)數(shù)據(jù)操作函數(shù)庫欄目數(shù)據(jù)操作函數(shù)(計(jì)數(shù)、獲取、排序、添加、修改、刪除)文章數(shù)據(jù)操作函數(shù)(計(jì)數(shù)、獲取、添加、修改、刪除)用戶數(shù)據(jù)操作函數(shù)(計(jì)數(shù)、獲取、添加、修改、刪除)橫幅數(shù)據(jù)操作函數(shù)(計(jì)數(shù)、獲取、添加、修改、刪除)鏈接數(shù)據(jù)操作函數(shù)(計(jì)數(shù)、獲取、添加、修改、刪除)數(shù)據(jù)實(shí)體類欄目類(set()、get()、__construct())文章類(set()、get()、__construct())用戶類(set()、get()、__construct())橫幅類(set()、get()、__construct())鏈接類(set()、get()、__construct())數(shù)據(jù)庫訪問類__contruct()方法select()方法insert()方法update()方法delete()方法__destruct()方法系統(tǒng)配置DBHostDBUserDBPasswordDBNameMySQL數(shù)據(jù)庫管理系統(tǒng)$data$data$data$sql$record$data$data第十頁,共71頁。9.2項(xiàng)目-面向?qū)ο蟮拈T戶網(wǎng)站的設(shè)計(jì)5、程序工作流程例解1:首頁熱點(diǎn)文章列表程序的數(shù)據(jù)流程第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)頁面:list_hot.php熱點(diǎn)文章列表程序方法:獲得數(shù)據(jù)庫article表中標(biāo)記為熱點(diǎn)的前n條記錄,逐條顯示其欄目標(biāo)題、文章標(biāo)題、發(fā)布時間等字段值。傳出到數(shù)據(jù)操作函數(shù)的參數(shù):記錄數(shù)量(本例中為12條,即$num=12)需要數(shù)據(jù)操作函數(shù)返回的數(shù)據(jù):Article類的對象組成的數(shù)組$data(其中每一個數(shù)組元素都封裝了一個文章類對象數(shù)據(jù))操作:在list_hot.php調(diào)用datahandle.php中的獲取前n條熱點(diǎn)文章函數(shù)getArticleByHot($num),將返回的數(shù)組逐條顯示在頁面中。程序:datahandle.php數(shù)據(jù)操作函數(shù)庫函數(shù):getArticleByHot($num);從list_hot.php收到的參數(shù):

$num=12傳出到數(shù)據(jù)庫訪問類的參數(shù):sql查詢語句(即$sql="select*fromarticle

wherehot=1orderbyserialdesclimit10")需要數(shù)據(jù)庫訪問類的select方法返回的數(shù)據(jù):Article類的對象組成的數(shù)組$data操作:調(diào)用dbaccess.php中數(shù)據(jù)庫操作類對象DbAccess()中的Select($sql)方法,將返回的數(shù)組再返回到list_hot.php程序:dbaccess.php數(shù)據(jù)庫操作類DbAccess方法:Select($sql);從getArticleByHot($num)函數(shù)傳入的參數(shù):$sql返回到getArticleByHot($num)函數(shù)的數(shù)據(jù):

Article類的對象組成的數(shù)組$data需要得到的數(shù)據(jù):

數(shù)據(jù)庫article表中的前n條熱點(diǎn)文章記錄的數(shù)據(jù)資源操作:數(shù)據(jù)庫服務(wù)器連接->打開數(shù)據(jù)表->執(zhí)行sql語句->將得到的數(shù)據(jù)資源打包成對象構(gòu)成數(shù)組MySQL數(shù)據(jù)庫管理系統(tǒng)$num$DATA$sql$DATA第十一頁,共71頁。9.2項(xiàng)目-面向?qū)ο蟮拈T戶網(wǎng)站的設(shè)計(jì)5、程序工作流程例解2:添加文章程序的數(shù)據(jù)流程第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)頁面:addarticle.php添加文章頁面方法:將從表單輸入的article信息打包成Article類對象,通過數(shù)據(jù)庫操作存入數(shù)據(jù)庫傳到數(shù)據(jù)操作函數(shù)insertArticle($data)的參數(shù):

攜帶了表單輸入數(shù)據(jù)的Article類對象$data操作:調(diào)用datahandle.php中的insertArticle($data)

函數(shù),將$data攜帶的文章數(shù)據(jù)寫入數(shù)據(jù)庫從insertArticle($data)

函數(shù)返回的數(shù)據(jù):TRUE或FALSE程序:datahandle.php數(shù)據(jù)操作函數(shù)庫函數(shù):insertArticle($data)

從addarticle.php傳入的參數(shù):

$data對象;操作:將$data對拆包成一個個屬性值,然后形成sql語句;傳出到數(shù)據(jù)庫訪問類的Insert($sql)方法的參數(shù):sql查詢語句(即$sql="insertintoarticle(title,topicid,author,content,editor)values($title,$topicid,$author,$content,$editor)"從數(shù)據(jù)庫訪問類的insert()方法返回的數(shù)據(jù):TRUE或FALSE操作:調(diào)用dbaccess.php中數(shù)據(jù)庫操作類DbAccess的Insert($sql)方法程序:dbaccess.php數(shù)據(jù)庫操作類DbAccess方法:Insert($sql);傳入的參數(shù):$sql返回到insertArticle($data)函數(shù)的數(shù)據(jù):TRUE或FALSE操作:數(shù)據(jù)庫服務(wù)器連接->打開數(shù)據(jù)表->執(zhí)行sql語句->將數(shù)據(jù)插入數(shù)據(jù)庫MySQL數(shù)據(jù)庫管理系統(tǒng)第十二頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)1、數(shù)據(jù)實(shí)體類

entity.php數(shù)據(jù)實(shí)體類定義<?phpclassTopic{//欄目類定義private$serial;private$title;private$parentid;private$location;private$navseq;function__get($property){return$this->$property;}function__set($property,$value){$this->$property=$value;}}classPoster{//橫幅類定義private$serial;private$picurl;private$thumburl;private$linkurl;private$title;function__get($property){return$this->$property;}function__set($property,$value){$this->$property=$value;}}classArticle{//文章類定義private$serial;private$title;private$content;private$author;private$updatetime;private$topicid;private$picurl;private$thumburl;private$editor;private$status;private$hot;function__get($property){return$this->$property;}function__set($property,$value){$this->$property=$value;}}第十三頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)1、數(shù)據(jù)實(shí)體類

entity.php數(shù)據(jù)實(shí)體類定義classLinks{//友情鏈接類定義private$serial;private$picurl;private$thumburl;private$linkurl;private$title;private$linkseq;function__get($property){return$this->$property;}function__set($property,$value){$this->$property=$value;}}classUser{//管理員類定義private$serial;private$userid;private$password;private$name;private$phone;private$email;private$privilige;private$question;private$answer;function__get($property){return$this->$property;}function__set($property,$value){$this->$property=$value;}}entity.php數(shù)據(jù)實(shí)體類定義classSysinfo{//系統(tǒng)信息類定義private$serial;private$title;private$ip;private$copyright;private$phone;private$email;private$address;private$permit;private$logo;private$banner;private$articlenum;private$linkstyle;private$posterstyle;private$navnum;private$linksnum;private$pptnum;private$hotnum;private$posternum;function__get($property){return$this->$property;}function__set($property,$value){$this->$property=$value;}}?>第十四頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫訪問類

dbaccess.php數(shù)據(jù)庫訪問類定義<?phpinclude_once('config.php');//數(shù)據(jù)庫訪問類classDbAccess{var$conn;//連接句柄

//構(gòu)造函數(shù)

publicfunction__construct(){$connect=mysql_connect(DBHost,DBUser,DBPassword)ordie('連接數(shù)據(jù)庫服務(wù)器失敗');mysql_select_db(DBName)ordie("打開數(shù)據(jù)庫失敗");mysql_query('setnamesutf8');$this->conn=$connect;//句柄賦值

}//析構(gòu)函數(shù)

publicfunction__destruct(){mysql_close($this->conn);}//獲取記錄數(shù)函數(shù)

publicfunctioncount($sql){if(empty($sql))returnfalse;if(empty($this->conn))returnfalse;$record=mysql_query($sql,$this->conn);$count=mysql_num_rows($record);return$count;//返回記錄數(shù)

}第十五頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫訪問類

第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)dbaccess.php數(shù)據(jù)庫訪問類定義//讀取記錄函數(shù)

publicfunctionselect($sql){if(empty($sql))returnfalse;if(empty($this->conn))returnfalse;$record=mysql_query($sql,$this->conn);if((!$record)or(empty($record))){@mysql_free_result($record);returnfalse;}$count=0;$data=array();while($row=@mysql_fetch_object($record)){$data[$count]=$row;$count++;}@mysql_free_result($record);//釋放內(nèi)存資源return$data;//返回記錄集數(shù)組

}//插入記錄函數(shù)

publicfunctioninsert($sql=""){if(empty($sql))return0;if(empty($this->conn))return0;$record=mysql_query($sql,$this->conn);if(!$record)return0;elsereturn$record;//返回插入的記錄

}第十六頁,共71頁。9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫訪問類

第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)dbaccess.php數(shù)據(jù)庫訪問類定義//更新記錄函數(shù)

publicfunctionupdate($sql=""){if(empty($sql))returnfalse;if(empty($this->conn))returnfalse;$record=mysql_query($sql,$this->conn);return$record;//返回更新的記錄

}//刪除記錄函數(shù)

publicfunctiondelete($sql=""){if(empty($sql))returnfalse;if(empty($this->conn))returnfalse;$record=mysql_query($sql,$this->conn);return$record;//返回刪除的記錄

}第十七頁,共71頁。9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫訪問類

第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)dbaccess.php數(shù)據(jù)庫訪問類定義//獲取表信息

publicfunctiongetTable(){

if(empty($this->conn))returnfalse;

$str="";$record=mysql_query('showtables',$this->conn);$i=0;

$table=array();

while($list=mysql_fetch_array($record)){$table[$i]=$list;

$i++;}

return$table;//返回表信息

}//獲取表內(nèi)容sql語句

functiongetSql($table){$sql="DROPTABLEIFEXISTS$table;\n";$record=mysql_query("SHOWCREATETABLE$table",$this->conn);$list=mysql_fetch_row($record);$sql.=$list[1].";\n\n";$rows=mysql_query("SELECT*FROM$table",$this->conn);$fieldsnum=mysql_num_fields($rows);$rowsnum=mysql_num_rows($rows);while($row=mysql_fetch_row($rows)){$comma="";$sql.="INSERTINTO$tableVALUES(";for($i=0;$i<$fieldsnum;$i++){$sql.=$comma."'".mysql_real_escape_string($row[$i])."'";$comma=",";}$sql.=");\n";}$sql.="\n";return$sql;//返回表內(nèi)容sql語句

}第十八頁,共71頁。9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫訪問類

第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)dbaccess.php數(shù)據(jù)庫訪問類定義//創(chuàng)建數(shù)據(jù)庫

functioncreateDB($sql){if(empty($this->conn))returnfalse;

$dropDB="DROPDATABASEIFEXISTS".DBName;$createDB="CREATEDATABASE".DBName;$createTB=($sql);

if(empty($createTB))returnfalse;if(!mysql_query($dropDB,$this->conn))returnfalse;if(!mysql_query($createDB,$this->conn))returnfalse;if(!mysql_select_db(DBName,$this->conn))returnfalse;$sqlRow=strtok($createTB,";");$i=1;while($sqlRow){if(!mysql_query($sqlRow,$this->conn))returnfalse;$sqlRow=strtok(";");$i++;

}}}?>第十九頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫操作函數(shù)庫

dbhandle.php數(shù)據(jù)操作函數(shù)定義-欄目數(shù)據(jù)操作函數(shù)<?phpclassDataHandler{include_once('entity.php');include_once('dbaccess.php');//獲取全部欄目數(shù)量

functiongetTopicCountAll(){$sql="select*fromtopic";$dbdata=newDbAccess();$result=$dbdata->count($sql);return$result;

}//獲取導(dǎo)航欄目數(shù)量

functiongetTopicCountByNav(){$sql="select*fromtopicwherenavseq>0";$dbdata=newDbAccess();$result=$dbdata->count($sql);return$result;}//根據(jù)父欄目id獲取子欄目數(shù)量

functiongetTopicCountByParent($parentid){$sql="select*fromtopicwhereparentid=$parentid";$dbdata=newDbAccess();$result=$dbdata->count($sql);return$result;}//根據(jù)id獲取欄目信息

functiongetTopic($serial){$sql="select*fromtopicwhereserial=$serial";$dbdata=newDbAccess();$result=$dbdata->select($sql);return$result;

}第二十頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫操作函數(shù)庫

dbhandle.php數(shù)據(jù)操作函數(shù)定義-欄目數(shù)據(jù)操作函數(shù)//獲取全部欄目信息

functiongetTopicAll(){$sql="select*fromtopicorderbyparentid";$dbdata=newDbAccess();$result=$dbdata->select($sql);return$result;}//根據(jù)父欄目id獲取欄目信息

functiongetTopicByParent($parentid){$sql="select*fromtopicwhereparentid=$parentid";$dbdata=newDbAccess();$result=$dbdata->select($sql);return$result;

}//獲取導(dǎo)航欄目信息

functiongetTopicByNav($num=8){$sql="select*fromtopicwherenavseq>0orderbynavseqlimit$num";$dbdata=newDbAccess();$result=$dbdata->select($sql);return$result;

}//根據(jù)首頁顯示位置獲取欄目信息

functiongetTopicByLocation($location){$sql="select*fromtopicwherelocation='$location'";$dbdata=newDbAccess();$result=$dbdata->select($sql);return$result;}第二十一頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫操作函數(shù)庫

//根據(jù)欄目id獲取欄目中所有子欄目idfunctiongetTopicTreeId($topicid){

$i=0;

static$j=0;

static$item=array();

$data=getTopicByParent($topicid);

while($row=$data[$i]){

$item[$j]=$row->serial;

$j++;

if(getTopicCountByParent($row->serial)>0){//判斷有沒有子欄目

getTopicTreeId($row->serial);

}

$i++;

}

return$item;

}//根據(jù)欄目id獲取欄目樹所有信息

functiongetTopicTree($topicid){$i=0; static$j=0; static$item=array();$data=getTopicByParent($topicid);while($row=$data[$i]){ static$indent=0;//定義縮進(jìn)量(0級) $item[$j]=array('indent'=>$indent,'topicid'=>$row->serial,'topictitle'=>$row->title,'navseq'=>$row->navseq,'location'=>$row->location); $j++;if(getTopicCountByParent($row->serial)>0){//判斷有沒有子欄目

$indent++;//子欄目增加縮進(jìn)量(每級子欄目+1) getTopicTree($row->serial); $indent--;//返回父欄目時減少縮進(jìn)量(每返回一級-1) }$i++;}return$item;

}第二十二頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫操作函數(shù)庫

//獲取最后一條欄目id

functiongetLastTopicId(){

$sql="selectserialfromtopicorderbyserialdesclimit1";

$dbdata=newDbAccess();$result=$dbdata->select($sql);return$result;

}//添加欄目信息

functioninsertTopic($data){$title=$data->title;$parentid=$data->parentid;$location=$data->location;$navseq=$data->navseq;$sql="insertintotopic(title,parentid,location,navseq)values('$title',$parentid,'$location',$navseq)";$dbdata=newDbAccess();$result=$dbdata->insert($sql);return$result;

}//修改欄目信息

functionupdateTopic($data){$serial=$data->serial;$title=$data->title;$parentid=$data->parentid;$location=$data->location;$navseq=$data->navseq;$sql="updatetopicsettitle='$title',parentid=$parentid,location='$location',navseq=$navseqwhereserial=$serial";$dbdata=newDbAccess();$result=$dbdata->update($sql);return$result;}第二十三頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫操作函數(shù)庫

dbhandle.php數(shù)據(jù)操作函數(shù)定義-欄目數(shù)據(jù)操作函數(shù)//根據(jù)欄目id刪除欄目信息

functiondeleteTopic($topicid){$sql="deletefromtopicwhereserial=$topicid";$dbdata=newDbAccess();$result=$dbdata->delete($sql);return$result;

}//根據(jù)父欄目id刪除欄目信息

functiondeleteTopicByParent($parentid){$sql="deletefromtopicwhere$parentid=$parentid";$dbdata=newDbAccess();$result=$dbdata->delete($sql);return$result;}//導(dǎo)航欄目左移調(diào)整順序

functionmoveNavseqLeft($navseq,$oldseq){$sql="updatetopicsetnavseq=navseq+1wherenavseq>=$navseqandnavseq<$oldseq";$dbdata=newDbAccess();$result=$dbdata->update($sql);return$result;}//導(dǎo)航欄目右移調(diào)整順序

functionmoveNavseqRight($navseq,$oldseq){$sql="updatetopicsetnavseq=navseq-1wherenavseq<=$navseqandnavseq>$oldseq";$dbdata=newDbAccess();$result=$dbdata->update($sql);return$result;}第二十四頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫操作函數(shù)庫

dbhandle.php數(shù)據(jù)操作函數(shù)定義-欄目數(shù)據(jù)操作函數(shù)//取消導(dǎo)航欄目調(diào)整順序

functioncancelNavseq($oldseq){$sql="updatetopicsetnavseq=navseq-1wherenavseq>$oldseq";$dbdata=newDbAccess();$result=$dbdata->update($sql);return$result;}//增加導(dǎo)航欄目調(diào)整順序

functionsetNavseq($navseq){$sql="updatetopicsetnavseq=navseq+1wherenavseq>=$navseq";$dbdata=newDbAccess();$result=$dbdata->update($sql);return$result;

}//取消首頁顯示欄目調(diào)整

functioncancelLocation($location){$sql="updatetopicsetlocation='none'wherelocation!='none'andlocation='$location'";$dbdata=newDbAccess();$result=$dbdata->update($sql);return$result;}第二十五頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫操作函數(shù)庫

dbhandle.php數(shù)據(jù)操作函數(shù)定義-欄目數(shù)據(jù)操作函數(shù)//根據(jù)欄目id獲取欄目樹下所有文章數(shù)量

functiongetArticleCountByTreeAdmin($topicid){$sql="select*fromarticlewheretopicid=$topicid";

$topictreeid=getTopicTreeId($topicid);

$i=0;

while($row=$topictreeid[$i]){

$sql.="ortopicid=$row";

$i++;

}$dbdata=newDbAccess();$result=$dbdata->count($sql);return$result;

}//根據(jù)欄目id獲取欄目樹下所有文章數(shù)量(允許顯示)

functiongetArticleCountByTree($topicid){

$sql="select*fromarticlewherestatus=1andtopicid=$topicid";

$topictreeid=getTopicTreeId($topicid);

$i=0;

while($row=$topictreeid[$i]){

$sql.="ortopicid=$row";

$i++;

}

$dbdata=newDbAccess();

$result=$dbdata->count($sql);

return$result;

}

第二十六頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫操作函數(shù)庫

dbhandle.php數(shù)據(jù)操作函數(shù)定義-文章數(shù)據(jù)操作函數(shù)//根據(jù)id獲取文章信息

functiongetArticle($serial){$sql="select*fromarticlewhereserial=$serial";$dbdata=newDbAccess();$result=$dbdata->select($sql);return$result;}//獲取指定數(shù)量熱點(diǎn)文章信息(允許顯示)

functiongetArticleByHot($num){$sql="select*fromarticlewherehot=1andstatus=1orderbyserialdesclimit$num";$dbdata=newDbAccess();$result=$dbdata->select($sql);return$result;}//根據(jù)欄目id分頁獲取欄目樹下所有文章信息

functiongetArticleByTreeAdminByPage($topicid,$page,$pagesize){$pagestart=($1)*$pagesize;$sql="select*fromarticlewheretopicid=$topicid";$topictreeid=getTopicTreeId($topicid);$i=0;while($row=$topictreeid[$i]){

$sql.="ortopicid=$row";

$i++;}$sql.="orderbyserialdesclimit$pagestart,$pagesize";$dbdata=newDbAccess();$result=$dbdata->select($sql);return$result;

}

第二十七頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫操作函數(shù)庫

dbhandle.php數(shù)據(jù)操作函數(shù)定義-文章數(shù)據(jù)操作函數(shù)//根據(jù)欄目id分頁獲取欄目樹下所有文章信息(允許顯示)

functiongetArticleByTreeByPage($topicid,$pagestart,$pagesize){$sql="select*fromarticlewherestatus=1andtopicid=$topicid";$topictreeid=getTopicTreeId($topicid);$i=0;while($row=$topictreeid[$i]){

$sql.="ortopicid=$row";

$i++;}$sql.="orderbyserialdesclimit$pagestart,$pagesize";$dbdata=newDbAccess();$result=$dbdata->select($sql);return$result;}//根據(jù)欄目id獲取所有文章信息(允許顯示)functiongetArticleByTree($topicid){$sql="select*fromarticlewheretopicid=$topicidandstatus=1orderbyserialdesc";$dbdata=newDbAccess();$result=$dbdata->select($sql);return$result;

}

第二十八頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫操作函數(shù)庫

dbhandle.php數(shù)據(jù)操作函數(shù)定義-文章數(shù)據(jù)操作函數(shù)//根據(jù)欄目id獲取欄目樹下指定數(shù)量的文章信息(允許顯示)

functiongetArticleByTreeByNum($topicid,$num){

$sql="select*fromarticlewherestatus=1andtopicid=$topicid";

$topictreeid=getTopicTreeId($topicid,$num);

$i=0;

while($row=$topictreeid[$i]){

$sql.="ortopicid=$row";

$i++;

}

$sql.="orderbyserialdesclimit$num";

$dbdata=newDbAccess();

$result=$dbdata->select($sql);

return$result;

}//獲取有標(biāo)題圖片的指定數(shù)量的文章信息

functiongetArticleByPic($num){$sql="select*fromarticlewherepicurl<>''orderbyserialdesclimit$num";$dbdata=newDbAccess();$result=$dbdata->select($sql);return$result;}//根據(jù)搜索關(guān)鍵字獲取文章信息(允許顯示)

functiongetArticleBySearch($field,$keyword){$sql="select*fromarticlewhere$fieldlike'%$keyword%'andstatus=1orderbyserialdesc";$dbdata=newDbAccess();$result=$dbdata->select($sql);return$result;

}第二十九頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫操作函數(shù)庫

dbhandle.php數(shù)據(jù)操作函數(shù)定義-文章數(shù)據(jù)操作函數(shù)//添加文章

functioninsertArticle($data){$title=$data->title;$content=$data->content;$author=$data->author;$topicid=$data->topicid;$editor=$data->editor;$sql="insertintoarticle(title,content,author,topicid,editor)values('$title','$content','$author',$topicid,'$editor')";$dbdata=newDbAccess();$result=$dbdata->insert($sql);return$result;

}//修改文章

functionupdateArticle($data){

$serial=$data->serial;

$title=$data->title;$content=$data->content;$author=$data->author;$topicid=$data->topicid;

$editor=$data->editor;$sql="updatearticlesettitle='$title',content='$content',author='$author',topicid=$topicid,editor='$editor'whereserial=$serial";$dbdata=newDbAccess();$result=$dbdata->update($sql);return$result;}//按id刪除文章信息

functiondeleteArticle($serial){$sql="deletefromarticlewhereserial=$serial";$dbdata=newDbAccess();$result=$dbdata->delete($sql);return$result;}第三十頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫操作函數(shù)庫

dbhandle.php數(shù)據(jù)操作函數(shù)定義-文章數(shù)據(jù)操作函數(shù)//按欄目id刪除文章信息

functiondeleteArticleByTopic($topicid){$sql="deletefromarticlewheretopicid=$topicid";$dbdata=newDbAccess();$result=$dbdata->delete($sql);return$result;

}//設(shè)置取消熱點(diǎn)

functionhotArticle($serial){$sql="updatearticlesethot=abs(hot-1)whereserial=$serial";$dbdata=newDbAccess();$result=$dbdata->update($sql);return$result;

}//允許禁止顯示文章

functionstatusArticle($serial){$sql="updatearticlesetstatus=abs(status-1)whereserial=$serial";$dbdata=newDbAccess();$result=$dbdata->update($sql);return$result;}//文章點(diǎn)擊數(shù)+1

functionvisitArticle($serial){$sql="updatearticlesetvisit=visit+1whereserial=$serial";$dbdata=newDbAccess();$result=$dbdata->update($sql);return$result;}

第三十一頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫操作函數(shù)庫

dbhandle.php數(shù)據(jù)操作函數(shù)定義-文章數(shù)據(jù)操作函數(shù)//文章點(diǎn)擊數(shù)+1functionvisitArticle($serial){$sql="updatearticlesetvisit=visit+1whereserial=$serial";$dbdata=newDbAccess();$result=$dbdata->update($sql);return$result;}//更新文章標(biāo)題圖片

functionupdateArticlePic($data){$serial=$data->serial;$picurl=$data->picurl;

$sql="updatearticlesetpicurl='$picurl'whereserial=$serial";$dbdata=newDbAccess();$result=$dbdata->update($sql);return$result;

}//更新文章視頻

functionupdateArticleVid($data){$serial=$data->serial;$vidurl=$data->vidurl();$sql="updatearticlesetvidurl='$vidurl'whereserial=$serial";$dbdata=newDbAccess();$result=$dbdata->update($sql);return$result;}第三十二頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫操作函數(shù)庫

dbhandle.php數(shù)據(jù)操作函數(shù)定義-橫幅數(shù)據(jù)操作函數(shù)//獲取所有橫幅項(xiàng)目信息

functiongetPosterAll(){$sql="select*fromposterorderbyserialdesc";$dbdata=newDbAccess();$result=$dbdata->select($sql);return$result;}//按數(shù)量獲取橫幅項(xiàng)目

functiongetPosterByNum($num){$sql="select*fromposterorderbyserialdesclimit$num";$dbdata=newDbAccess();$result=$dbdata->select($sql);return$result;

}//獲取指定橫幅項(xiàng)目信息

functiongetPoster($posterid){$sql="select*fromposterwhereserial=$posterid";$dbdata=newDbAccess();$result=$dbdata->select($sql);return$result;

}//添加橫幅中的項(xiàng)目

functioninsertPoster($data){$title=$data->title;$linkurl=$data->linkurl;$sql="insertintoposter(title,linkurl)values('$title','$linkurl')";$dbdata=newDbAccess();$result=$dbdata->insert($sql);return$result;}第三十三頁,共71頁。第9章使用PHP面向?qū)ο蠹夹g(shù)的網(wǎng)站系統(tǒng)9.3面向?qū)ο蟮拈T戶網(wǎng)站的實(shí)現(xiàn)3、數(shù)據(jù)庫操作函數(shù)庫

dbhandle.php數(shù)據(jù)操作函數(shù)定義-橫幅數(shù)據(jù)操作函數(shù)//修改橫幅中的項(xiàng)目

functionupdatePoster($data){$serial=$data->serial;$title=$data->title;$linkurl=$data->linkurl;$sql="updatepostersettitle='$title',linkurl='$linkurl'whereserial=$serial";$dbdata=newDbAccess();$result=$dbdata->update($sql);return$result;}//更新橫幅項(xiàng)目圖片

functionupdatePosterPic($data){

$serial=$data->serial;$picurl=$data->picurl;$thumburl=$data->thumburl;$sql="updatepostersetpicurl='$picurl',thumburl='$thumburl'whereserial=$serial";$dbdata=newDbAccess();$result=$dbdata->update($sql);return$result;

}//刪除橫幅項(xiàng)目

functiondeletePoster($posterid){$sql="deletefromposterwhereserial=$posterid";$dbdata=new

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論