日期:2014-05-17 浏览次数:20374 次
class db{
public $conn;
private static $h = "localhost";
private static $u = "root";
private static $p = "123123";
private static $d = "air";
function __construct(){
$this->conn=mysqli_connect(self::$h,self::$u,self::$p,self::$d);
$this->conn->query('SET NAMES UTF8');
//mysqli_query($this->conn,'SET NAMES UTF8');
}
public function getOne($sql,$resultType=MYSQL_ASSOC){//只取一条
$q=$this->conn->query($sql);
$rt=$q->fetch_array($resultType);
return $rt;
}
}
//下面是一个继承类,就是上面的那个db我写好了后。有只要引用数据库(只取一条的,取多条我未写出)便来继承。这样写不好吗?谢谢
class airVia extends db{
public function doSql(){
$sql='select * from xls1 where id=1';//实际中的语句复杂,只是测试
$r=$this->getOne($sql);//db::getone($sql);不行
return $r;
}
}//airVia
//使用此类
$wc=new airVia($v);echo $wc->doSql();
public function __construct(){
parent::__construct();
}