Home > Backend Development > PHP Tutorial > 大神仙,老神仙,不大不小中神仙,给看看呗.为何继承了就没数据值了呢。小弟我啥没理解呢

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

WBOY
Release: 2016-06-13 12:40:50
Original
936 people have browsed it

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

本帖最后由 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);
Copy after login
继承
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template