<?php
/**
* SQL access
*
*/
DEFINE ('SQL_LOGIN', 'root');
DEFINE ('SQL_PWD', 'pwd');
DEFINE ('SQL_DB', 'dbname');
DEFINE ('SQL_HOST', 'localhost');
/**
* Includes
*/
require_once 'package.oLimit.php';
/**
* mysql testing
*/
/**
* Connection
*/
$hCon = mysql_connect (SQL_HOST, SQL_LOGIN, SQL_PWD);
mysql_select_db (SQL_DB, $hCon);
/**
* Query
*/
$sQuery = <<<sql
SELECT id FROM table
sql;
$rRes = mysql_query ($sQuery, $hCon);
try {
/**
* Creating the mysqlLimit object using the factory, with arbitrary values (here, staring at offset 20, and retrieving the 10 next results)
*/
$limit = LimitFactory::factory ('MYSQL', $rRes, 20, 10);
/**
* while loop
*/
while ($limit -> valid()) {
/**
* Displaying some values from mysqlLimit object
*/
echo '<p><strong>Internal Position : ', $limit -> getInternalPos (), ' && Row Offset : ',$limit -> getExternalPos (),' => </strong></p>';
/**
* Displaying current result array
*/
echo '<pre>', print_r ($limit -> current ()), '</pre>';
/**
* Jumping to the next position
*/
$limit -> next ();
}
} catch (Exception $e) {
echo $e -> getMessage (), ' on line ', $e -> getLine ();
}
mysql_close ($hCon);
/**
* array testing
*/
$aTab = range (1, 1000, 5);
try {
$limit = LimitFactory::factory ('ARRAY', $aTab, 150, 20);
while ($limit -> valid()) {
echo $limit -> key (), ' => ', $limit -> current (), '<br />';
$limit -> next ();
}
} catch (Exception $e) {
echo $e -> getMessage (), ' on line ', $e -> getLine ();
}
?>
|