php学习笔记之面向对象编程

代码如下:
PHP
class db {
private $MysqLi; //数据库连接
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 "
"; 
print_r ( $chanelInfo );

class a {
protected function aa(){
echo 222;
}
}
class b extends a{
function bb(){
$this->aa();
}
}
$c = new b();
$c->bb();


public 公有的:本类,子类,外部对象都可以调用
protected 受保护的:本类 子类,可以执行,外部对象不可以调用
private 私有的:只能本类执行,子类与外部对象都不可调用

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...