PHP5 OOP編程中的代理與異常(2)_PHP教程
教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!
推薦:詳細(xì)介紹php5編程中的異常處理1 首先是try,catch <?php $path = "D:\\in.txt"; try //檢測(cè)異常 { file_open($path); } catch(Exception $e) //捕獲異常 { echo $e->getMessage(); } function
為此,你需要修改DBQuery對(duì)象以便包括所有的函數(shù)—它們操作一個(gè)來(lái)自DB對(duì)象的結(jié)果資源。當(dāng)執(zhí)行查詢以調(diào)用DB對(duì)象的相應(yīng)函數(shù)并且返回它的結(jié)果時(shí),你需要使用存儲(chǔ)的結(jié)果。下列函數(shù)將被添加:
列表2:使用代理擴(kuò)展DBQuery類。
class DBQuery { ..... public function fetch_array() { if (! is_resource($this->result)) { throw new Exception('Query not executed.'); } return $this->db->fetch_array($this->result); } public function fetch_row() { if (! is_resource($this->result)) { throw new Exception('Query not executed.'); } return $this->db->fetch_row($this->result); } public function fetch_assoc() { if (! is_resource($this->result)) { throw new Exception('Query not executed.'); } return $this->db->fetch_assoc($this->result); } public function fetch_object() { if (! is_resource($this->result)) { throw new Exception('Query not executed.'); } return $this->db->fetch_object($this->result); } public function num_rows() { if (! is_resource($this->result)) { throw new Exception('Query not executed.'); } return $this->db->num_rows($this->result); } } |
每個(gè)函數(shù)的實(shí)現(xiàn)相當(dāng)簡(jiǎn)單。它首先進(jìn)行檢查,以確保已經(jīng)執(zhí)行查詢,然后把任務(wù)代理到DB對(duì)象,返回它的結(jié)果就好象它是查詢對(duì)象本身(稱作是基本數(shù)據(jù)庫(kù)函數(shù))一樣。
分享:Zend Framework 入門(mén)——頁(yè)面布局Zend Framework 的頁(yè)面布局模塊——Zend_Layout——既可以跟 MVC 一起使用,也可以單獨(dú)使用。本文只討論與 MVC 一起使用的情況。 1. 布局腳本 在 application/views 下
相關(guān)PHP教程:
- PHPNOW安裝Memcached擴(kuò)展方法詳解
- php記錄頁(yè)面代碼執(zhí)行時(shí)間
- PHP中獎(jiǎng)概率的抽獎(jiǎng)算法程序代碼
- apache設(shè)置靜態(tài)文件緩存方法介紹
- php對(duì)圖像的各種處理函數(shù)代碼小結(jié)
- PHP 關(guān)于訪問(wèn)控制的和運(yùn)算符優(yōu)先級(jí)介紹
- 關(guān)于PHP語(yǔ)言構(gòu)造器介紹
- php/js獲取客戶端mac地址的實(shí)現(xiàn)代碼
- php5.5新數(shù)組函數(shù)array_column使用
- PHP preg_match的匹配多國(guó)語(yǔ)言的技巧
- php 中序列化和json使用介紹
- php采集文章中的圖片獲取替換到本地
PHP教程Rss訂閱編程教程搜索
PHP教程推薦
- php curl的深入解析
- PHP時(shí)間戳與日期之間轉(zhuǎn)換的實(shí)例介紹
- 詳解PHP內(nèi)置訪問(wèn)資源的超時(shí)時(shí)間 time_out file_get_contents read_file
- PHP實(shí)例:精確到每一秒鐘的在線人數(shù)顯示代碼
- PHP教程之入門(mén)需要掌握的幾種功能代碼
- 小荷才露尖尖角 中國(guó)的PHP社群介紹
- cmd運(yùn)行php
- 用PHP程序?yàn)樽约壕W(wǎng)站打造一個(gè)搜索引擎
- 加速動(dòng)態(tài)網(wǎng)站 MySQL索引分析和優(yōu)化
- 深入phpMyAdmin的安裝與配置的詳細(xì)步驟
- 相關(guān)鏈接:
- 教程說(shuō)明:
PHP教程-PHP5 OOP編程中的代理與異常(2)
。