您的位置:首页 > 编程语言 > PHP开发

PHP面向对象----继承特性

2013-04-25 19:23 155 查看
将数据库常用的操作(连接数据库,获得所有数据,获得一条记录,获得一列记录,获得一条索引数组,获得一条关联数组)都给封装到db.class.php里面,谁需要谁继承这个类

注意:提交封装的类文件

<?php

class db

{

private $hostname;

private $user;

private $pass;

private $dbname;

private $linkflag;

private $charset;

public function __construct($host,$user,$pass,$dbname,$charset)

{

$this->hostname=$host;

$this->user=$user;

$this->pass=$pass;

$this->dbname=$dbname;

$this->charset=$charset;

$this->linkflag=mysql_connect($this->hostname,$this->user,$this->pass);

mysql_select_db($this->dbname,$this->linkflag) or die('连接失败!');

mysql_query("set names ".$this->charset);

}

public function getAll($sql){

$result = mysql_query($sql);

$rows = array();

while($row=mysql_fetch_assoc($result)){

$rows[] = $row;

}

return $rows;

}

public function getOne($sql){

$result = mysql_query($sql);

$row = mysql_fetch_assoc($result);

return $row;

}

public function __destruct()

{

mysql_close($this->linkflag);

}

}

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: