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