$this->dbCurrentnot $this->$dbCurrent

解决方案 »

  1.   

    And you must include the mysql class file in the page.
      

  2.   

    $this->$dbCurrent -〉$this->dbCurrent
      

  3.   

    呵呵,没想到PHP版块有这么多热心的朋友
    看样子没来错(我是做.NET的,对PHP也比较有兴趣) caotian2000(乡约北京) ( ) 信誉:100    Blog  2006-9-14 13:09:21  得分: 0  
       
    你没有实例化第一个类
    鉴于在Function函数中无法访问外部变量,所以我把require_once("../DAL.class.php");
    require_once("../938bbs/config.inc.php");
    放在了构造函数中,并在构造函数中对该类进行了实例化:$this->$dbCurrent = new mysql("dns=".$dbhost.";uid=".$dbuser.";pwd=".$dbpw.";dbname=".$dbname."");并试图在其他function函数中使用$this->$dbCurrent不必再使用
    require_once("../DAL.class.php");
    require_once("../938bbs/config.inc.php");
     从而达到打开数据库,关闭数据库的目的,就比如
    function GetCount($strCondition="")
    {$this->$dbCurrent->select_db($dbname);
    $this->$dbSqlcount = "select count(1) from tarticlecate ";
    if ($strCondition!="")
    {
    $this->$dbSqlcount = $this->$dbSqlcount." where ".$strCondition;
    }$row=$this->$dbCurrent->fetch_array($dbCurrent->query($this->$dbSqlcount,$this->$connCurrent));
    $recordcount = $row[0];//记录总数
    $this->$dbCurrent->db_close();
    return $recordcount;}@zeroleonhart,@iasky(C#_ASP_PHP) 
    我试试将$this->$dbCurrent -〉$this->dbCurrent
    谢谢你们,稍后再请教大家
      
     
      

  4.   

    代码还没仔细看,等我回家再帮你看看。几点建议:
    1 对开头的那一大堆变量定义,完全可以将其分组并显示的声明为一个数组,然后隐式声明其元素。这样代码会减少很多。
    比如:
    // 分页参数设置
    var $CurrentPage; //当前页号
    var $MaxPage; //最大页号
    var $Linage; //每页行数
    var $PaginalFormat; //翻页样式
    var $MaxCount; //记录总数(指查询返回数)
    var $offset; //偏移量,指记录的开始这样声明:
    var $Page;然后等以后想用到上面那些属性的时候,直接:
    $this->Page['CurrentPage'];
    $this->Page['MaxPage'];
    $this->Page['Linage'];
    ...就可以了。
    关于类与类之间的引用,你可以继承的方式,然后直接实例化子类就可以了,这样在子类里面就可以调用父类和子类的所有方法,除了父类声明的私有成员外!里面的方法了。关于2个类互相调用时,可以在调用的类里面写个方法,把被调用的类的实例做为一个参数传进来。
      

  5.   

    谢谢楼上的兄弟
    经过修改,代码现在已经部分通过了编译
    不过还有个小问题:class  articlecateBLL
    {

    var $dbSql;
    var $dbSqlcount;

    var $dbCurrent;
    var $connCurrent;
    var $currentDBHost;
    var $currentDBUser;
    var $currentDBPwd;
    var $currentDBName;

    function articlecateBLL()
    {
    require_once("../DAL.class.php");
    require_once("../938bbs/config.inc.php");
    $this->dbSql = "";
    $this->dbSqlcount = "";
    $this->currentDBHost = $dbhost;
    $this->currentDBUser = $dbuser;
    $this->currentDBPwd = $dbpw;
    $this->currentDBName = $dbname;


    $this->dbCurrent = new mysql("dns=".$this->currentDBHost.";uid=".$this->currentDBUser.";pwd=".$this->currentDBPwd.";dbname=".$this->currentDBName."");
    $this->connCurrent = $this->dbCurrent->config("dns=".$this->currentDBHost.";uid=".$this->currentDBUser.";pwd=".$this->currentDBPwd.";dbname=".$this->currentDBName."");



    function GetCount($strCondition="")
    {

    $this->dbCurrent->select_db($this->currentDBName);
    $this->dbSqlcount = "select count(1) from tarticlecate ";
    if ($strCondition!="")
    {
    $this->dbSqlcount = $this->dbSqlcount." where ".$strCondition;
    }

    $row=$this->dbCurrent->fetch_array($this->dbCurrent->query($this->dbSqlcount,$this->connCurrent));
    $recordcount = $row[0];//记录总数
    $this->dbCurrent->db_close();
    return $recordcount;

    }

             function GetPageRecord($strCondition="",$strOrderby=" order by articlecateid desc",$strPageLimit="")
    {
    $this->dbCurrent->select_db($this->currentDBName);

    $this->dbSql="select * from tarticlecate  "; if ($strCondition != "")
    {
    $this->dbSql = $this->dbSql." where ".$strCondition;
    }

    if ($strPageLimit != "")
    {
    $this->dbSql = $this->dbSql.$strPageLimit;
    }

    $this->dbSql = $this->dbSql.$strCondition;


    $result=$this->dbCurrent->query($this->dbSql,$this->connCurrent);
    $this->dbCurrent->db_close();
    return $result;
    }}在调用页面实例化该类为$BLL后
    能够正确的调用:
    $BLL->GetCount();但是紧跟着下一个函数$BLL->GetPageRecord("","",$p->limitStr());
    却提示Warning: mysql_select_db(): Access denied for user: 'ODBC@localhost' (Using password: NO) in e:\wwwroot\website\w_z_98_01\wwwroot\DAL.class.php on line 67Warning: mysql_select_db(): A link to the server could not be established in e:\wwwroot\website\w_z_98_01\wwwroot\DAL.class.php on line 67
    select * from tarticlecate LIMIT 0, 10
    @ShadowSniper(青春不等人呀...) 非常感谢你的指导:)
    不过现在事情赶的急,我PHP还是处于入门阶段,所以很多东西还是按照.net的方式在思考
    难免有些不习惯的地方
    希望以后有机会向你请教
      

  6.   

    warning一般不用管它,直接用在该语句的前面加"@"就好了.【quote】
    function GetPageRecord($strCondition="",$strOrderby=" order by articlecateid desc",$strPageLimit="")【/quote】方法定义时,最好把没有默认值的参数放在最右侧,$BLL->GetPageRecord("","",$p->limitStr());你这个$p->limitStr()参数是想传给$strPageLimit的吧?可实际它在你定义的方法里面对应的位置是$strOrderby这个参数,这个问题似乎在c#中也存在吧?所以可能会造成参数传递错误。把两个参数换下位置就可以了。改为这样就行了。function GetPageRecord($strCondition="",$strPageLimit="",$strOrderby=" order by articlecateid desc")