php學(xué)習(xí)筆記之面向?qū)ο缶幊?/h1>
更新時(shí)間:2012年12月29日 09:47:22 作者:
一個(gè)php初學(xué)者的一個(gè)學(xué)習(xí)筆記的面向?qū)ο缶幊虒?shí)例,有需要學(xué)習(xí)的朋友可參考下,腳本之家也更新了很多大家可以查閱下
復(fù)制代碼 代碼如下:
<?php
class db {
private $mysqli; //數(shù)據(jù)庫連接
private $options; //SQL選項(xiàng)
private $tableName; //表名
public function __construct($tabName) {
$this->tableName = $tabName;
$this->db ();
}
private function db() {
$this->mysqli = new mysqli ( 'localhost', 'root', '', 'hdcms' );
$this->mysqli->query("SET NAMES GBK");
}
public function fields($fildsArr) {
if (empty ( $fildsArr )) {
$this->options ['fields'] = '';
}
if (is_array ( $fildsArr )) {
$this->options ['fields'] = implode ( ',', $fildsArr );
} else {
$this->options ['fields'] = $fildsArr;
}
return $this;
}
public function order($str) {
$this->options ['order'] = "ORDER BY " . $str;
return $this;
}
public function select() {
$sql = "SELECT {$this->options['fields']} FROM {$this->tableName} {$this->options['order']}";
return $this->query ( $sql );
}
private function query($sql) {
$result = $this->mysqli
->query ( $sql );
$rows = array ();
while ( $row = $result->fetch_assoc () ) {
$rows [] = $row;
}
return $rows;
}
private function close() {
$this->mysqli
->close ();
}
function __destruct() {
$this->close ();
}
}
$chanel = new db ( "hdw_channel" );
$chanelInfo = $chanel->fields ( 'id,cname,cpath' )
->select ();
echo "<pre>";
print_r ( $chanelInfo );
class a {
protected function aa(){
echo 222;
}
}
class b extends a{
function bb(){
$this->aa();
}
}
$c = new b();
$c->bb();
public 公有的:本類,子類,外部對(duì)象都可以調(diào)用
protected 受保護(hù)的:本類 子類,可以執(zhí)行,外部對(duì)象不可以調(diào)用
private 私有的:只能本類執(zhí)行,子類與外部對(duì)象都不可調(diào)用
您可能感興趣的文章:- 以實(shí)例全面講解PHP中多進(jìn)程編程的相關(guān)函數(shù)的使用
- PHP編程函數(shù)安全篇
- php高級(jí)編程-函數(shù)-鄭阿奇
- PHP編程之高級(jí)技巧——利用Mysql函數(shù)
- PHP高級(jí)編程實(shí)例:編寫守護(hù)進(jìn)程
- 淺析PHP編程中10個(gè)最常見的錯(cuò)誤
- 談?wù)勑率秩绾螌W(xué)習(xí)PHP網(wǎng)絡(luò)編程
- PHP編程實(shí)現(xiàn)多維數(shù)組按照某個(gè)鍵值排序的方法小結(jié)【2種方法】
- PHP編程風(fēng)格規(guī)范分享
- PHP 組件化編程技巧
- PHP編程中的常見漏洞和代碼實(shí)例
- php函數(shù)式編程簡(jiǎn)單示例
相關(guān)文章
-
PHP函數(shù)用法詳解【初始化、嵌套、內(nèi)置函數(shù)等】
這篇文章主要介紹了PHP函數(shù)用法,結(jié)合實(shí)例形式詳細(xì)分析了PHP函數(shù)初始化、嵌套、內(nèi)置函數(shù)等相關(guān)定義、原理與操作注意事項(xiàng),需要的朋友可以參考下 2020-06-06
-
PHP在不同頁面間傳遞Json數(shù)據(jù)示例代碼
本文為大家介紹下PHP如何在不同頁面間傳遞Json數(shù)據(jù),具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下哈,希望對(duì)大家有所幫助 2013-06-06
-
PHP中空字符串介紹0、null、empty和false之間的關(guān)系
用PHP開發(fā)那么久,PHP中空字符串、0、null、empty和false之間的關(guān)系總是有些不確定的東西。遇到它們應(yīng)該用哪個(gè)方法函數(shù)去處理 2012-09-09
最新評(píng)論
復(fù)制代碼 代碼如下:
<?php
class db {
private $mysqli; //數(shù)據(jù)庫連接
private $options; //SQL選項(xiàng)
private $tableName; //表名
public function __construct($tabName) {
$this->tableName = $tabName;
$this->db ();
}
private function db() {
$this->mysqli = new mysqli ( 'localhost', 'root', '', 'hdcms' );
$this->mysqli->query("SET NAMES GBK");
}
public function fields($fildsArr) {
if (empty ( $fildsArr )) {
$this->options ['fields'] = '';
}
if (is_array ( $fildsArr )) {
$this->options ['fields'] = implode ( ',', $fildsArr );
} else {
$this->options ['fields'] = $fildsArr;
}
return $this;
}
public function order($str) {
$this->options ['order'] = "ORDER BY " . $str;
return $this;
}
public function select() {
$sql = "SELECT {$this->options['fields']} FROM {$this->tableName} {$this->options['order']}";
return $this->query ( $sql );
}
private function query($sql) {
$result = $this->mysqli
->query ( $sql );
$rows = array ();
while ( $row = $result->fetch_assoc () ) {
$rows [] = $row;
}
return $rows;
}
private function close() {
$this->mysqli
->close ();
}
function __destruct() {
$this->close ();
}
}
$chanel = new db ( "hdw_channel" );
$chanelInfo = $chanel->fields ( 'id,cname,cpath' )
->select ();
echo "<pre>";
print_r ( $chanelInfo );
class a {
protected function aa(){
echo 222;
}
}
class b extends a{
function bb(){
$this->aa();
}
}
$c = new b();
$c->bb();
public 公有的:本類,子類,外部對(duì)象都可以調(diào)用
protected 受保護(hù)的:本類 子類,可以執(zhí)行,外部對(duì)象不可以調(diào)用
private 私有的:只能本類執(zhí)行,子類與外部對(duì)象都不可調(diào)用
您可能感興趣的文章:
- 以實(shí)例全面講解PHP中多進(jìn)程編程的相關(guān)函數(shù)的使用
- PHP編程函數(shù)安全篇
- php高級(jí)編程-函數(shù)-鄭阿奇
- PHP編程之高級(jí)技巧——利用Mysql函數(shù)
- PHP高級(jí)編程實(shí)例:編寫守護(hù)進(jìn)程
- 淺析PHP編程中10個(gè)最常見的錯(cuò)誤
- 談?wù)勑率秩绾螌W(xué)習(xí)PHP網(wǎng)絡(luò)編程
- PHP編程實(shí)現(xiàn)多維數(shù)組按照某個(gè)鍵值排序的方法小結(jié)【2種方法】
- PHP編程風(fēng)格規(guī)范分享
- PHP 組件化編程技巧
- PHP編程中的常見漏洞和代碼實(shí)例
- php函數(shù)式編程簡(jiǎn)單示例
相關(guān)文章
PHP函數(shù)用法詳解【初始化、嵌套、內(nèi)置函數(shù)等】
這篇文章主要介紹了PHP函數(shù)用法,結(jié)合實(shí)例形式詳細(xì)分析了PHP函數(shù)初始化、嵌套、內(nèi)置函數(shù)等相關(guān)定義、原理與操作注意事項(xiàng),需要的朋友可以參考下2020-06-06PHP在不同頁面間傳遞Json數(shù)據(jù)示例代碼
本文為大家介紹下PHP如何在不同頁面間傳遞Json數(shù)據(jù),具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下哈,希望對(duì)大家有所幫助2013-06-06PHP中空字符串介紹0、null、empty和false之間的關(guān)系
用PHP開發(fā)那么久,PHP中空字符串、0、null、empty和false之間的關(guān)系總是有些不確定的東西。遇到它們應(yīng)該用哪個(gè)方法函數(shù)去處理2012-09-09