PHP5 OOP編程中的代理與異常(2)_PHP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:詳細介紹php5編程中的異常處理1 首先是try,catch <?php $path = "D:\\in.txt"; try //檢測異常 { file_open($path); } catch(Exception $e) //捕獲異常 { echo $e->getMessage(); } function
為此,你需要修改DBQuery對象以便包括所有的函數(shù)—它們操作一個來自DB對象的結果資源。當執(zhí)行查詢以調用DB對象的相應函數(shù)并且返回它的結果時,你需要使用存儲的結果。下列函數(shù)將被添加:
列表2:使用代理擴展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); } } |
每個函數(shù)的實現(xiàn)相當簡單。它首先進行檢查,以確保已經(jīng)執(zhí)行查詢,然后把任務代理到DB對象,返回它的結果就好象它是查詢對象本身(稱作是基本數(shù)據(jù)庫函數(shù))一樣。
分享:Zend Framework 入門——頁面布局Zend Framework 的頁面布局模塊——Zend_Layout——既可以跟 MVC 一起使用,也可以單獨使用。本文只討論與 MVC 一起使用的情況。 1. 布局腳本 在 application/views 下
相關PHP教程:
- 相關鏈接:
- 教程說明:
PHP教程-PHP5 OOP編程中的代理與異常(2)
。