首页 >后端开发 >php教程 >大神仙,老神仙,不大不小中神仙,给看看呗.为何继承了就没数据值了呢。我啥没理解呢?

大神仙,老神仙,不大不小中神仙,给看看呗.为何继承了就没数据值了呢。我啥没理解呢?

WBOY
WBOY原创
2016-06-23 14:18:08913浏览

本帖最后由 bixuewei 于 2013-08-03 23:25:10 编辑

<?php$config = array();$config['DB_HOST']='localhost';$config['DB_USER']='root';$config['DB_PASS']='';$config['DB_NAME']='hfdb';foreach($config as $name =>$val){	define($name,$val);}$dsn = "mysql:host=".DB_HOST.";dbname=".DB_NAME;$dbo = new PDO($dsn,DB_USER,DB_PASS);/*$sql="select * from task";$stmt =$dbo->prepare($sql);$stmt ->execute();$results = $stmt -> fetchALL(PDO::FETCH_ASSOC);print_r($results); $stmt ->closeCursor();*/class DB_Connect{	public $db;			protected function __construct($dbo=NULL)	{			$dsn = "mysql:host=".DB_HOST.";dbname=".DB_NAME;			try			{			$this->db =new PDO($dsn,DB_USER,DB_PASS);			}			catch(Exception $e)			{				die($e->getMessage());			}	}}class Task extends DB_Connect{			public function __construct($dbo=NULL,$useData=NULL)	{		parent::__construct($dbo);	}		private function _LoadEventTask ($id=NULL)	{		$sql="SELECT * FROM `task`";		try		{			$stmt = $this->db->prepare($sql);			$stmt ->execute();			$results = $stmt -> fetchALL(PDO::FETCH_ASSOC);			$stmt ->closeCursor();			return $results;		}		catch( Exception $e)		{			die($e->getMessage() );		}	}}$ssss= new Task($dbo);var_dump ($ssss);

回复讨论(解决方案)

大神们都睡了,又要失眠啦。

object(Task)#2 (1) {
  ["db"]=>
  object(PDO)#3 (0) {
  }
}

真勤劳的老神仙啊。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn