php新手求助各位大神!!!!!!!!

傲娇强 2013-08-21 01:08:52
这个是我的数据库连接类,要用换红线部分的方法

这是我的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

各位大神帮帮忙啊!!!!!!!
...全文
207 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
傲娇强 2013-08-21
  • 打赏
  • 举报
回复
引用 9 楼 xuzuning 的回复:
你在新的top.php中 function select_menu($p_id,$type_class) { $ret_types = $db->query_to_array("..... 那这个 $db 不是在外面吗?
用了global,问题解决了
tony4geek 2013-08-21
  • 打赏
  • 举报
回复
你的$ret_types   这个查询有数据吗?
xuzuning 2013-08-21
  • 打赏
  • 举报
回复
你在新的top.php中 function select_menu($p_id,$type_class) { $ret_types = $db->query_to_array("..... 那这个 $db 不是在外面吗?
傲娇强 2013-08-21
  • 打赏
  • 举报
回复
引用 7 楼 xuzuning 的回复:
你 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
我把代码改了,在类的最下面实例化了,免得每次用都要填参数,然后在函数里面 global $db; 现在不报错了,但是 菜单没出来,数据库里面是有数据的,新手自学php,求指点啊
xuzuning 2013-08-21
  • 打赏
  • 举报
回复
你 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
傲娇强 2013-08-21
  • 打赏
  • 举报
回复
我把代码贴出来,帮忙看哈 这个是数据库类的
<?
$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;
             }	
           ?>	
傲娇强 2013-08-21
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
实例化 MysqlTool 类时需要传递 4 个参数,而你一个都没有
$db = new MysqlTool("localhost", "root", "", "db_dahuangfeng");
在类的最下面实例化了,但是在top.php的函数里面取不到这个类的查询方法
xuzuning 2013-08-21
  • 打赏
  • 举报
回复
不可以!那些参数是用于连接数据库的 数据库都不连接,如何查询?
傲娇强 2013-08-21
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
实例化 MysqlTool 类时需要传递 4 个参数,而你一个都没有
那可不可以,不实例化,就能够用那个方法呢
傲娇强 2013-08-21
  • 打赏
  • 举报
回复
那可不可以,不实例化,就能够用那个方法呢
xuzuning 2013-08-21
  • 打赏
  • 举报
回复
实例化 MysqlTool 类时需要传递 4 个参数,而你一个都没有

20,359

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧