<?php
require_once("class.db.result.php");
require_once("class.db.cnx.mysql.php");
/*
-------------------------------------------------------------------------
dbMysql Class
A mysql wrapper class to be used to handle manipulation of mysql resultsets.
-------------------------------------------------------------------------
Developer
Name -- Haddad Said.
Date -- 10-08-2005
Version -- 1.2
-------------------------------------------------------------------------
Member Functions (Basic)
1.Constructor -- Obvious!
2.getArray -- Returns a row from a resultset as an array.
3.getObject -- Returns a row from a resultset as an object.
4.getID -- Returns mysql_insert_id().
5.seek -- sets the seeker at a particular row in the resultset.
6.getNumRows -- Returns the number of rows in the resultset.
-------------------------------------------------------------------------
*/
class dbResultMysql extends dbResult
{
/*
-------------------------------------------------------------------------
Class Constructor
Parameters:
$db - The db connectivity object's reference
$result - database resultset resource.
Notes:
Sets up the initial values of the Mysql Database connectivity.
Example Usage:
$result = new dbResultMysql($this, $this->db_result)
-------------------------------------------------------------------------
*/
function dbResultMysql(&$db_cnx, $result)
{
parent::dbResult(&$db_cnx, $result);
}
/*
-------------------------------------------------------------------------
Method getArray
A method to fetch a row from the resultset as an array
Parameters:
Notes:
This method returns the row as an array of the fields in the recordset.
It is better suited for use in a while loop.
If $this->db_result is empty it will return false.
Example Usage:
while($row = $db->getArray())
{
?>
<tr><td><?=$row['0']?></td><td><?=$row['1']?></td><td><?=$row['2']?></td></tr>
<?
}
-------------------------------------------------------------------------
*/
function getArray()
{
if(!$this->db_result)
{
return false;
}
//If the row counter has been initialized....
if(isset($this->pg_row))
{
//...,we verify it is still in the boundaries...
if($this->pg_row >= $this->pg_size)
{
return false;
}
//...and then we increment it.
$this->pg_row++;
}
return mysql_fetch_array($this->db_result);
}
/*
-------------------------------------------------------------------------
Method getObject
A method to fetch a row from the resultset as an object.
Parameters:
Notes:
This method returns the row as an object whose member variables are
the fields in the recordset.
If $this->db_result is empty it will return false.
Example Usage:
$row = $db->getObject();
?>
<tr><td><?=$row->user_id?></td><td><?=$row->user_name?></td><td><?=$row->user_email?></td></tr>
<?
-------------------------------------------------------------------------
*/
function getObject()
{
if(!$this->db_result)
{
return false;
}
//If the row counter has been initialized....
if(isset($this->pg_row))
{
//...,we verify it is still in the boundaries...
if($this->pg_row >= $this->pg_size)
{
return false;
}
//...and then we increment it.
$this->pg_row++;
}
return mysql_fetch_object($this->db_result);
}
/*
-------------------------------------------------------------------------
Method getID
A method to fetch the ID of the last insert sql statement
Parameters:
Notes:
This method fetches the ID of the last insert sql statement.
It can be used to generate unique strings for each recordset in the table.
If $this->db_result is empty it will return false.
Example Usage:
$mysqlID = $db->getID();
-------------------------------------------------------------------------
*/
function getID()
{
if(!$this->db_result)
{
return false;
}
return mysql_insert_id($this->db_cnx->db_cnx);
}
/*
-------------------------------------------------------------------------
Method seek
A method to set the seeker at a particular row in the resultset
Parameters:
$row -- row number to set the seeker at.
Notes:
Example Usage:
$db->seek(8);
-------------------------------------------------------------------------
*/
function seek($row)
{
if(!$this->db_result)
{
return false;
}
@mysql_data_seek($this->db_result, $row);
return true;
}
/*
-------------------------------------------------------------------------
Method getNumRows
A method to fetch the number of rows in the resultset resource
Parameters:
Notes:
This method returns the number of rows in the resultset resource.
If $this->db_result is empty it will return false.
Example Usage:
echo "Number of rows in the Result set is " . $db->getNumRows();
-------------------------------------------------------------------------
*/
function getNumRows()
{
if(!$this->db_result)
{
return false;
}
return mysql_num_rows($this->db_result);
}
}
?>