大神仙,老神仙,不大不小中神仙,给看看呗.为何继承了就没数据值了呢。我啥没理解呢?
本帖最后由 bixuewei 于 2013-08-03 23:25:10 编辑
<?php<br />
$config = array();<br />
$config['DB_HOST']='localhost';<br />
$config['DB_USER']='root';<br />
$config['DB_PASS']='';<br />
$config['DB_NAME']='hfdb';<br />
<br />
<br />
foreach($config as $name =>$val)<br />
{<br />
define($name,$val);<br />
}<br />
$dsn = "mysql:host=".DB_HOST.";dbname=".DB_NAME;<br />
$dbo = new PDO($dsn,DB_USER,DB_PASS);<br />
<br />
/*<br />
<br />
$sql="select * from task";<br />
<br />
$stmt =$dbo->prepare($sql);<br />
<br />
$stmt ->execute();<br />
$results = $stmt -> fetchALL(PDO::FETCH_ASSOC);<br />
print_r($results); <br />
$stmt ->closeCursor();<br />
*/<br />
<br />
<br />
<br />
class DB_Connect{<br />
<br />
public $db;<br />
<br />
<br />
protected function __construct($dbo=NULL)<br />
{<br />
<br />
$dsn = "mysql:host=".DB_HOST.";dbname=".DB_NAME;<br />
try<br />
{<br />
$this->db =new PDO($dsn,DB_USER,DB_PASS);<br />
}<br />
catch(Exception $e)<br />
{<br />
die($e->getMessage());<br />
}<br />
}<br />
}<br />
<br />
class Task extends DB_Connect<br />
{ <br />
public function __construct($dbo=NULL,$useData=NULL)<br />
{<br />
parent::__construct($dbo);<br />
}<br />
<br />
private function _LoadEventTask ($id=NULL)<br />
{<br />
$sql="SELECT * FROM `task`";<br />
<br />
try<br />
{<br />
$stmt = $this->db->prepare($sql);<br />
$stmt ->execute();<br />
$results = $stmt -> fetchALL(PDO::FETCH_ASSOC);<br />
$stmt ->closeCursor();<br />
return $results;<br />
}<br />
catch( Exception $e)<br />
{<br />
die($e->getMessage() );<br />
}<br />
}<br />
}<br />
$ssss= new Task($dbo);<br />
var_dump ($ssss);
로그인 후 복사