class db {
私有 $mysqli; // 数据库连接
private $options; //SQL 选项
private $tableName; // 表名
public function __construct($tabName) {
$this->tableName = $tabName;
$this->db ();
}
私有函数 db() {
$this->mysqli = new mysqli ( 'localhost', 'root', '', 'hdcms' );
$this->mysqli->query("SET NAMES GBK");
}
公共函数字段($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;
返回 $this;
}
public function select() {
$sql = "SELECT {$this->options['fields']} FROM {$this->tableName} {$this->options ['命令']}”;
return $this->query ( $sql );
}
私有函数查询($sql) {
$result = $this->mysqli
->query ( $sql );
$rows = array ();
while ( $row = $result->fetch_assoc () ) {
$rows [] = $row;
}
返回 $rows;
}
private function close() {
$this->mysqli
->close ();
}
function __destruct() {
$this->close ();
}
}
$chanel = new db ("hdw_channel");
$chanelInfo = $chanel->fields ('id,cname,cpath')
->select ();
回显“
”; <br>print_r ( $chanelInfo );
<p>class a { <br> protected 函数 aa(){ <br> echo 222; <br> } <br>} <br>b 类扩展了 a{ <br> function bb(){ <br> $this->aa(); <br> } <br>} <br>$c = new b(); <br>$c->bb();<br></p>