<?php
class Combo
{
var $array_cd_nm;
function Combo($array_cd_nm)
{
$this->$array_cd_nm = $array_cd_nm;
} function getList()
{
return $this->$array_cd_nm; }
} class CityCombo extends Combo {
var $sql;
var $db;
function CityCombo ($str="") {
$this->$db = new Tkcm01;// Tkcm01是DB类
// DB连接
$dberrcode = $this->$db->dbConn();
if ($dberrcode != 0) {
$msg = "DB连接失败";
outLogfileCmn("../TKRJ39/Combo",__LINE__,"err:".$msg);
return;
} if($str==""){
$this->$sql = " select t0.j0_prefecture_cd,t0.j0_prefecture_name from prefecture t0 ";
}else if(ereg("^[0-9]+$", $str)){
$this->$sql = " select j0_prefecture_name from prefecture where j0_prefecture_cd = '{$str}'";
}else{
$this->$sql = " select j0_prefecture_cd from prefecture where j0_prefecture_name = '{$str}'";
}
echo $this->$db;
}
function getCityList()
{ if(is_object($this->$db)){
echo "dddddd";
}
$sql = $this->$sql;
$dberrcode = $this->$db->dbParseSql($sql, $stmt);
if ($dberrcode == 0) {
$db->dbDefineByName($stmt, "J0_PREFECTURE_CD" , $cd );
$db->dbDefineByName($stmt, "J0_PREFECTURE_NAME", $name);
$dberrcode = $db->dbExecute($stmt);
if ($dberrcode == 0) {
while($db->dbFetch($stmt)){
$arr_cdNm[$cd]=$name;
}
}
$this->$array_cd_nm =$arr_cdNm; }
if ($dberrcode != 0) {
$msg = $db->getErrorMsg();
$smarty->assign("err_message", getNameForCode(C_TK_MESSAGE, "TK".getLangType()."043"));
outLogfileCmn("../TKRJ08/TKRJ0823",__LINE__,"err:".$msg.",sql:".$sql);
}
$db->dbFreeSql($stmt);
$db->dbDisconn(); return parent::getList();
}
}
?> 在上面的程序中为什么我在构造函数里给$db付的值是无效的(this->$db = new Tkcm01),给$sql的值确是有效的。并且用echo $this->$db输出的时候输出的是$sql的值,为什么this->$db的值被覆盖了呢, 已经好几天了还没解决,求大家帮帮忙吧。
应该是$this->db,不是$db
还有就是确定在实例化你的数据库类的时候包含的数据库类文件