I started learning OOP PHP from yesterday. Learnt the basic concept. Now what i am trying to do is create a class that shows data from a table. provided the table name and other parameters. here is the code.
<?php
$conn=mysql_connect('localhost','root','') or die("Could not connect to server.");
$db=mysql_select_db("recess",$conn) or die("Database recess not found.");
class Database
{
public function selects($table, $rows = '*', $where = null, $order = null)
{
$q = 'SELECT '.$rows.' FROM '.$table;
if($where != null)
$q .= ' WHERE '.$where;
if($order != null)
$q .= ' ORDER BY '.$order;
$query = @mysql_query($q);
if($query)
{
// I do not understand this part untill "<END>" comment is seen
$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> Untill here
}
}
return true;
}
else
{
return false;
}
}
public function getResult()
{
return $this->result;
}
}
?>
<?php
$show = new Database();
$show->selects("category");
echo $show->getResult(); //this simply prints "Array" I dunno why
?>
Please help me understand.
Thanks in advance