在自定义函数内部应该不能直接调用$db的,所以在第十行前应重新处理一下
$ndb=new db_sql;
$row=$row = $ndb->query($sql);

解决方案 »

  1.   

    刚才写错了是这样
    $row = $ndb->query($sql);
      

  2.   

    function check_user($nicker,$password,$level=2)
    {
    global $ndb;
      

  3.   

    <?
    include("db_mysql.inc");
    $db = new db_Sql;//第3行
    $db->connect("borrow","localhost","root","");
    function check_user($nicker,$password,$level=2)
    {
      global $db;
     if($nicker=="")
       return 0;
     $sql = "select password from user_info where nicker='$nicker'";
     $row = $db->query($sql);//第10行
     if($row->next_record() == $password)
        return 1;
     else
        return 0;
    }
    ?>
      

  4.   

    你的自定义函数中无法识别类$db,你可以这样改进
    方案一:
    <?
    include("db_mysql.inc");
    $db = new db_Sql;//第3行
    $db->connect("borrow","localhost","root","");
    function check_user($nicker,$password,$level=2)
    {
      gloable &db;     //改进后增进的指令行
      if($nicker=="")
       return 0;
     $sql = "select password from user_info where nicker='$nicker'";
     $row = $db->query($sql);//第10行
     if($row->next_record() == $password)
        return 1;
     else
        return 0;
    }
    ?>方案二
    <?
    include("db_mysql.inc");
    $db = new db_Sql;//第3行
    $db->connect("borrow","localhost","root","");
    function check_user($nicker,$password,$level=2,$db)  //改进后将$db作为参数传入函数内
    {
     if($nicker=="")
       return 0;
     $sql = "select password from user_info where nicker='$nicker'";
     $row = $db->query($sql);//第10行
     if($row->next_record() == $password)
        return 1;
     else
        return 0;
    }
    ?>
      

  5.   

    <?
    include("db_mysql.inc");
    $db = new db_Sql;//第3行
    $db->connect("borrow","localhost","root","");
    function check_user($nicker,$password,$level=2)
    {
      global $db;
     if($nicker=="")
       return 0;
     $sql = "select password from user_info where nicker='$nicker'";
     $row = $db->query($sql);//第10行
     if($row->next_record() == $password)//第11行
        return 1;
     else
        return 0;
    }
    ?>按照这个方案改了后,在第11行又除了问题,Call to a member function on a non-object ,这又是什么问题呀?
    哎,我这是第一次用类来做项目,就遇到这个问题,真不习惯。
      

  6.   

    <?
    include("db_mysql.inc");
    $db = new db_Sql;//第3行
    $db->connect("borrow","localhost","root","");
    function check_user($nicker,$password,$level=2)
    {
      global $db;
     if($nicker=="")
       return 0;
     $sql = "select password from user_info where nicker='$nicker'";
     $db->query($sql);//第10行
     if($db->next_record() == $password)//第11行
        return 1;
     else
        return 0;
    }
    ?>