php學(xué)習(xí)筆記之面向?qū)ο缶幊?/h1>
更新時間:2012年12月29日 09:47:22 作者:
一個php初學(xué)者的一個學(xué)習(xí)筆記的面向?qū)ο缶幊虒嵗行枰獙W(xué)習(xí)的朋友可參考下,腳本之家也更新了很多大家可以查閱下
復(fù)制代碼 代碼如下:
<?php
class db {
private $mysqli; //數(shù)據(jù)庫連接
private $options; //SQL選項
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 公有的:本類,子類,外部對象都可以調(diào)用
protected 受保護(hù)的:本類 子類,可以執(zhí)行,外部對象不可以調(diào)用
private 私有的:只能本類執(zhí)行,子類與外部對象都不可調(diào)用
您可能感興趣的文章:
相關(guān)文章
-
PHP函數(shù)用法詳解【初始化、嵌套、內(nèi)置函數(shù)等】
這篇文章主要介紹了PHP函數(shù)用法,結(jié)合實例形式詳細(xì)分析了PHP函數(shù)初始化、嵌套、內(nèi)置函數(shù)等相關(guān)定義、原理與操作注意事項,需要的朋友可以參考下 2020-06-06
-
PHP在不同頁面間傳遞Json數(shù)據(jù)示例代碼
本文為大家介紹下PHP如何在不同頁面間傳遞Json數(shù)據(jù),具體實現(xiàn)如下,感興趣的朋友可以參考下哈,希望對大家有所幫助 2013-06-06
-
PHP中空字符串介紹0、null、empty和false之間的關(guān)系
用PHP開發(fā)那么久,PHP中空字符串、0、null、empty和false之間的關(guān)系總是有些不確定的東西。遇到它們應(yīng)該用哪個方法函數(shù)去處理 2012-09-09
最新評論
復(fù)制代碼 代碼如下:
<?php
class db {
private $mysqli; //數(shù)據(jù)庫連接
private $options; //SQL選項
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 公有的:本類,子類,外部對象都可以調(diào)用
protected 受保護(hù)的:本類 子類,可以執(zhí)行,外部對象不可以調(diào)用
private 私有的:只能本類執(zhí)行,子類與外部對象都不可調(diào)用
您可能感興趣的文章:
相關(guān)文章
PHP函數(shù)用法詳解【初始化、嵌套、內(nèi)置函數(shù)等】
這篇文章主要介紹了PHP函數(shù)用法,結(jié)合實例形式詳細(xì)分析了PHP函數(shù)初始化、嵌套、內(nèi)置函數(shù)等相關(guān)定義、原理與操作注意事項,需要的朋友可以參考下2020-06-06PHP在不同頁面間傳遞Json數(shù)據(jù)示例代碼
本文為大家介紹下PHP如何在不同頁面間傳遞Json數(shù)據(jù),具體實現(xiàn)如下,感興趣的朋友可以參考下哈,希望對大家有所幫助2013-06-06PHP中空字符串介紹0、null、empty和false之間的關(guān)系
用PHP開發(fā)那么久,PHP中空字符串、0、null、empty和false之間的關(guān)系總是有些不確定的東西。遇到它們應(yīng)該用哪個方法函數(shù)去處理2012-09-09