Copy Code code as follows:
<?php
Class DB {
Private $mysqli; Database connection
Private $options; SQL options
Private $tableName; Table name
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 publicly owned: This class, subclasses, and external objects can all be called
Protected protected: This class subclass, which can be executed, cannot be invoked by external objects
Private: Only this class can be executed, subclasses and external objects are not callable