如何调用类外的变量
<br />require_once("../data/a.php");<br /><br />class mydatabase {<br /><br /> // 链接数据库<br /> function opendata($database) {<br /> //方法一<br /> global $dbhost , $dbname , $dbuser , $dbpwd , $dbprefix , $db_language;<br /> //方法二<br /> require_once("../data/a.php");<br /> //方法三<br /> //在a.php把变量全部定义成常量<br /> define('DB_HOST' , 'test');<br /> //调用的时候直接 使用DB_HOST<br /> echo DB_HOST;<br /> <br /> }<br /><br /><br /> //查询一条记录<br /> function ReadOne($database) {<br /> self::opendata($database);<br /> $rs = mysql_query("SELECT * from fcc where id=1");<br /> $row = mysql_fetch_array($rs);<br /> self::closedata();<br /> return $row["date"];<br /> <br /> }<br /><br />}<br />
<br /><?php<br /> define('MYHOST', 'localhost');<br /> define('MYUSER', 'cccc');<br /> define('MYPWD', '123456');<br />?><br />
<br /><?php<br />require_once("../data/a.php");<br /><br />class mydatabase{<br /><br /> private $myhost;<br /> private $myuser;<br /> private $mypwd;<br /><br /> public function __construct(){<br /> $this->myhost = MYHOST;<br /> $this->myuser = MYUSER;<br /> $this->mypwd = MYPWD;<br /> }<br /><br /> function opendata($database){<br /> $linkid = mysql_connect($this->myhost, $this->myuser, $this->mypwd);<br /> }<br /><br />}<br />?><br />
<br /><?php<br />return array(<br /> 'myhost' => 'localhost',<br /> 'myuser' => 'cccc',<br /> 'mypwd' => '123456'<br />);<br />
<br><?php <br />class mydatabase{<div class="clear"> </div>