【发布时间】:2014-02-08 04:25:37
【问题描述】:
所以我正在使用这个名为 Database 的类并使用一种方法(选择)
从给定的查询中获取所有结果
我正在尝试回显或打印结果?
//数据库.php
class Database{
public function select($table, $rows = '*', $where = null, $order = null){
$q = 'SELECT '.$rows.' FROM '.$table;
if($where != null)
$q .= ' WHERE '.$where;
if($order != null)
$q .= ' ORDER BY '.$order;
if($this->tableExists($table))
{
$query = @mysql_query($q);
if($query)
{
$this->numResults = mysql_num_rows($query);
for($i = 0; $i < $this->numResults; $i++)
{
$r = mysql_fetch_array($query);
$key = array_keys($r);
for($x = 0; $x < count($key); $x++)
{
// Sanitizes keys so only alphavalues are allowed
if(!is_int($key[$x]))
{
if(mysql_num_rows($query) > 1)
$this->result[$i][$key[$x]] = $r[$key[$x]];
else if(mysql_num_rows($query) < 1)
$this->result = null;
else
$this->result[$key[$x]] = $r[$key[$x]];
}//end if
}//end for
}//end for
return true;
}//endif
else
{
return false;
}
}
else
return false;
}
}
这就是我试图输出结果的地方,但我不知道该怎么做才能回显/打印结果。
//select.php
include(includes/database.php);
$db = new Database();
$table = 'user';
$rows;
$match = $db->select($table,$rows);
var_dump($db->match);
有人告诉我,我不必接触 Database 类中的任何代码。
【问题讨论】:
-
var_dump($db->result)可能是个线索。 -
使用带有
mysql_ugh*函数的类真是太浪费了。 -
我正在使用 var_dump 返回 NULL。 @Fred-ii-我理解你的仇恨。我刚刚被带到项目中期并试图解决这个问题。
-
您假设首先包含该类,然后实例化它。颠倒
$db = new Database(); include(includes/database.php);的顺序 -
@i-- 感谢您的理解,但我仍然从 var_dump 获得 NULL