<?php
include_once("PaginationFactory.php");
include_once("DatabaseQueriesFactory.php");
include_once("ConnectionManagerFactory.php");
include_once("DBTypes.php");
$resultPage = $_REQUEST["resultPage"];
/**
* Get the corresponding ConnectionManager object w.r.t to database specified in DB_TYPE constant(DBTypes.php).
* Factory Method.
* One can use their own connection object. I used here ConnectionManager Class to connect to the database.
* You can find the ConnectionManager Class at the following url http://www.phpclasses.org/browse.html/package/1429.html
*/
$objConnectionClass = ConnectionManagerFactory::getInstanceOf(DB_TYPE);
/**
* Invoke the doConnection object to make a connection to the specified database
*/
$objConnectionClass->doConnection();
/**
* Get the connectionHandle (Base Class Method).
*/
$conn = $objConnectionClass->getConnectionHandle();
/**
* Select the database.
*/
$objConnectionClass->selectDatabase();
$selquery = "select * from alumini order by firstname";
/**
* $edited = "F";
* $selquery = "SELARTICLES"; //(Procedure name).
* $params = array("@edited"=>array($edited=>SQLCHAR, false)); // (Procedure Parameters).
*/
$params = null;
/**
* Get the corresponding DatabaseQueries object w.r.t to database specified in DB_TYPE constant(DBTypes.php).
* Factory Method.
*/
/**
* if $params in null it means the query is of type inline otherwise it is a procedure and provide the $params associative array
* as follows:-
* $params -- Associative array eg. array("@edited"=>array($edited=>SQLCHAR, false));
* where -- @edited is input/output paramter,
* -- $edited is the value of Input Parameter @edited,
* -- SQLCHAR is a the MSSQL Constant for CHAR column type,
* -- false indicates @edited is not an output parameter.
* For Pagination we need to pass the result set and connection object as parameters. One can use their own component to get the
* result set and connection object. In this example I used my own DatabaseQueries component to get the result set and execute queries.
*/
$objDatabaseClass = DatabaseQueriesFactory::getInstanceOf($selquery, $conn, $params, DB_TYPE);
/**
* Call the executeQuery method.
*/
if(!$objDatabaseClass->executeQuery())
{
die("Cannot query");
}
/* $result = your resultset fetched from database by calling base class method getResultSet(). */
$result = $objDatabaseClass->getResultSet();
/**
* get the number of rows in a result set.
*/
$rowcount = $objDatabaseClass->getNumRows();
/**
* Get the corresponding Pagination object w.r.t to database specified in DB_TYPE constant(DBTypes.php).
* Factory Method.
*/
$objPagination = PaginationFactory::getInstanceOf($result, 1, $conn, $rowcount, $resultPage, DB_TYPE);
/**
* Get the page data by calling getPageData() method.
*/
while($row = $objPagination->getPageData())
{
/* display your data */
}
/**
* display the page navigation links (Base Class Method).
*/
echo $objPagination->getPageNav();
unset($objConnectionClass);
unset($objDatabaseClass);
unset($objPagination);
?>
|