I need to write a method to return the number of rows I have in my table. This code I've written so far;
<pre><?php
class Database
{
private $connected=false;
private $user,$pass,$host;
private $db;
private $result=array();
public function initialize($user, $pass, $host)
{
$this->user=$user;
$this->pass=$pass;
$this->host=$host;
return $this;
}
function connect($dbname)
{
$this->db=mysql_connect($this->host,$this->user,$this->pass) or
die('<h1>Unable to connect to database</h1>' . mysql_error());
mysql_select_db($dbname) or die('<h1>Unable to select database</h1>' . mysql_error());
return $this;
}
function query($sqlstring)
{
$query= mysql_query($sqlstring,$this->db) or die('<h1>Unable to query database</h1>' . mysql_error());
while($record=mysql_fetch_assoc($query)){
$this->result[]=$record;
}
return $this->result;
}
/*function numRows($sq)
{
$this->$query="select count(*) as numRows from members";
}*/
}
$db = new Database();
print_r($db->initialize("root","project","localhost")->connect("mmsplus")->
query("SELECT count(*) as num FROM members"));
?></pre>
So far this does the work but I need a separate method for the counting, any help is appreciated.