国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php學習筆記之面向?qū)ο缶幊?/h1>
2024-09-04 11:43:42
字體:
供稿:網(wǎng)友

一個php初學者的一個學習筆記的面向?qū)ο缶幊虒嵗?有需要學習的朋友可參考參考.

PHP實例代碼如下:

  1. class db {  
  2.     private $mysqli//數(shù)據(jù)庫連接  
  3.     private $options//SQL選項  
  4.     private $tableName//表名  
  5.     public function __construct($tabName) {  
  6.         $this->tableName = $tabName;  
  7.         $this->db ();  
  8.     }  
  9.     private function db() {  
  10.         $this->mysqli = new mysqli ( 'localhost''root''''hdcms' );  
  11.         $this->mysqli->query("SET NAMES GBK");  
  12.     }  
  13.     public function fields($fildsArr) {  
  14.         if (emptyempty ( $fildsArr )) {  
  15.             $this->options ['fields'] = '';  
  16.         }  
  17.         if (is_array ( $fildsArr )) {  
  18.             $this->options ['fields'] = implode ( ','$fildsArr );  
  19.         } else {  
  20.             $this->options ['fields'] = $fildsArr;  
  21.         }  
  22.         return $this;  
  23.     }  
  24.     public function order($str) {  
  25.         $this->options ['order'] = "ORDER BY " . $str;  
  26.         return $this;  
  27.     }  
  28.     public function select() {  
  29.         $sql = "SELECT {$this->options['fields']} FROM {$this->tableName}  {$this->options['order']}";  
  30.         return $this->query ( $sql );  
  31.     }  
  32.     private function query($sql) {  
  33.         $result = $this->mysqli  
  34.             ->query ( $sql );  
  35.         $rows = array ();  
  36.         while ( $row = $result->fetch_assoc () ) {  
  37.             $rows [] = $row;  
  38.         }  
  39.         return $rows;  
  40.     }  
  41.     private function close() {  
  42.         $this->mysqli  
  43.             ->close ();  
  44.     }  
  45.     function __destruct() {  
  46.         $this->close ();  
  47.     }  
  48. }  
  49. $chanel = new db ( "hdw_channel" );  
  50. $chanelInfo = $chanel->fields ( 'id,cname,cpath' )  
  51.     ->select ();  
  52. echo "<pre>";  
  53. print_r ( $chanelInfo ); 
  54.  
  55. class a {  
  56.     protected  function aa(){  
  57.         echo 222;  
  58.     }  
  59. }  
  60. class b extends a{  
  61.     function bb(){  
  62.         $this->aa();  
  63.     }  
  64. }  
  65. $c = new b();  
  66. $c->bb(); 

public 公有的:本類,子類,外部對象都可以調(diào)用.

protected 受保護的:本類 子類,可以執(zhí)行,外部對象不可以調(diào)用.

private 私有的:只能本類執(zhí)行,子類與外部對象都不可調(diào)用.

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

主站蜘蛛池模板: 河源市| 佛冈县| 辉县市| 辽阳县| 门头沟区| 亳州市| 阿克陶县| 汤阴县| 巴塘县| 新和县| 屏边| 南丹县| 宁海县| 黄石市| 洪江市| 夏邑县| 东阳市| 太原市| 巩留县| 洪泽县| 盐城市| 乐业县| 灌南县| 乡城县| 渭南市| 拜泉县| 鲁山县| 喜德县| 田林县| 洪江市| 桃源县| 从化市| 汉源县| 屯昌县| 抚顺县| 宁南县| 花莲市| 闽清县| 五指山市| 崇左市| 四川省|