这个是我的数据库连接类,要用换红线部分的方法这是我的index.php页面,调用了这个类文件,和top部分现在问题出在 top.php上面,我用一个函数来生成菜单,但是调用不到query_to_array()这个查询方法了
自己查资料,用new也不行下面是报错的内容Warning: Missing argument 1 for MysqlTool::__construct(), called in E:\Project\2013-8\DaHuangFeng\top.php on line 10 and defined in E:\Project\2013-8\DaHuangFeng\inc\connclass.php on line 7各位大神帮帮忙啊!!!!!!!
PHP

解决方案 »

  1.   

    实例化  MysqlTool 类时需要传递 4 个参数,而你一个都没有
      

  2.   

    $db = new MysqlTool("localhost", "root", "", "db_dahuangfeng");
    在类的最下面实例化了,但是在top.php的函数里面取不到这个类的查询方法
      

  3.   

    我把代码贴出来,帮忙看哈
    这个是数据库类的
    <?
    $isdebug = false;class MysqlTool
    {
    public $conn;
    public function __construct($server, $name, $pwd, $dbname, $charset='utf8')

    $this->conn = mysql_connect($server, $name, $pwd);  
    mysql_query("use $dbname", $this->conn); 
    mysql_query("set character set $charset", $this->conn); 
    mysql_query("set names $charset", $this->conn);
    }  //insert update delete
    public function exe($sql)
    {
    global $isdebug;


    $temp = mysql_query($sql, $this->conn);

    $err = mysql_error();
    if (empty($err) == false && $isdebug == true)
    {
    print( '<br /><hr style="color:green" /><font color="#0000FF">错误信息:' . mysql_error() .  '</font><br /><font color="red">执行SQL:' . $sql . '</font>' );
    }
    else if (empty($err) == false)
    {
    die("system error");
    }

    return $temp;


    // select *....
    public function query_to_array($sql)

    $temp_array = array();
    $result = $this->exe($sql);
    while ($row = mysql_fetch_array($result))
    {
    array_push($temp_array, $row);
    }
    return $temp_array;

    // select top 1 id from tb...
    public function query_single($sql)
    {
    $result = $this->exe($sql);
    if ($row = mysql_fetch_row($result))
    {
    return $row[0];
    }
    }

    function __destruct()

    mysql_close($this->conn);
    }
    }
    $db = new MysqlTool("localhost", "root", "", "db_dahuangfeng");
    ?> 这是top.php的,在引用top.php的文件里面已经include_once了这个类
     <?  
                  function select_menu($p_id,$type_class)
                  {                                         
                      $ret_types  = $db->query_to_array("select * from tb_types where p_id = $p_id and type_class = $type_class order by type_id desc;");
                      $html = '';                      
                      foreach($ret_types as $k => $v)
                       {
                         $html .= '<li><a href="';
                         if($type_class == 1)
                         {
                            $html .= 'about';
                         }
                         if($type_class == 2)
                         {
                            $html .= 'news';
                         }
                         $html .= '.php?t=' . $v['type_id'] . '">' . $v['type_name'] . '</a></li>';
                       }
                       return $html;
                 }
               ?>
      

  4.   

    你 top.php 的第10行不就只是 $query = new MysqlTool(); 吗?错误信息不也指示到那里吗
    Warning: Missing argument 1 for MysqlTool::__construct(), called in E:\Project\2013-8\DaHuangFeng\top.php on line 10 
      

  5.   

    我把代码改了,在类的最下面实例化了,免得每次用都要填参数,然后在函数里面 global $db;
    现在不报错了,但是 菜单没出来,数据库里面是有数据的,新手自学php,求指点啊
      

  6.   

    你在新的top.php中
    function select_menu($p_id,$type_class)
    {                                         
       $ret_types  = $db->query_to_array(".....那这个 $db 不是在外面吗?
      

  7.   

    你的$ret_types   这个查询有数据吗?