mafiq
asked on
PearDB
Anyone with an idea of how I can get the Pager up and running on a Linux platform using
PHP/MySql. I want paginated results from mysql database.
PHP/MySql. I want paginated results from mysql database.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have extracted the Pager.php file into same folder with my php file with following code:
<?php
require 'Pager.php';
$db = mysql_connect("localhost", "root");
mysql_select_db("uzexams", $db) or die();
$sql = "select * from faculty";
$result = mysql_query($sql);
$limit = 10;
$from = 50;
$pager = new Pager ($result, $from, $limit);
$data = $pager->build();
if (DB::isError($data))
{
die (DB::errorMessage($data));
}
if (!$data)
{
die ('There were no results');
}
echo "<html><body>";
echo $data['numrows'] . " Results found";
echo 'Page '. $data['current'] . " of " . $data['numpages'];
echo $data['limit'] . " results per page";
echo "<a href='".$PHP_SELF."'"."?fr om='".$dat a['next']. "'".">'".$ data['rema in']."'"." Next->"."< /a>";
foreach ($data['pages'] as $page => $start_row)
{
echo "<a href='$PHP_SELF?from=$star t_row'>$pa ge</a>";
}
while ($row = $pager->fetchRow(DB_FETCHM ODE_ASSOC) )
{
echo $row['id'] . "\n";
}
echo '</body></html>';
?>
When I try running it, the following error results:
Fatal error: Cannot instantiate non-existent class: pager in /var/www/html/PageTest.php on line 9
<?php
require 'Pager.php';
$db = mysql_connect("localhost",
mysql_select_db("uzexams",
$sql = "select * from faculty";
$result = mysql_query($sql);
$limit = 10;
$from = 50;
$pager = new Pager ($result, $from, $limit);
$data = $pager->build();
if (DB::isError($data))
{
die (DB::errorMessage($data));
}
if (!$data)
{
die ('There were no results');
}
echo "<html><body>";
echo $data['numrows'] . " Results found";
echo 'Page '. $data['current'] . " of " . $data['numpages'];
echo $data['limit'] . " results per page";
echo "<a href='".$PHP_SELF."'"."?fr
foreach ($data['pages'] as $page => $start_row)
{
echo "<a href='$PHP_SELF?from=$star
}
while ($row = $pager->fetchRow(DB_FETCHM
{
echo $row['id'] . "\n";
}
echo '</body></html>';
?>
When I try running it, the following error results:
Fatal error: Cannot instantiate non-existent class: pager in /var/www/html/PageTest.php
Try
require "./Pager.php";
You may find that your include_path string setting is not standard.
From the PHP manual ...
include_path string
Specifies a list of directories where the require(), include() and fopen_with_path() functions look for files. The format is like the system's PATH environment variable: a list of directories separated with a colon in UNIX or semicolon in Windows. Example 3-3. UNIX include_path
include_path=.:/home/httpd /php-lib
Example 3-4. Windows include_path
include_path=".;c:\www\php lib"
The default value for this directive is . (only the current directory).
To see that the setting is try ...
<?php phpinfo(); ?>
as info.php
This will show you all your system's settings for PHP.
require "./Pager.php";
You may find that your include_path string setting is not standard.
From the PHP manual ...
include_path string
Specifies a list of directories where the require(), include() and fopen_with_path() functions look for files. The format is like the system's PATH environment variable: a list of directories separated with a colon in UNIX or semicolon in Windows. Example 3-3. UNIX include_path
include_path=.:/home/httpd
Example 3-4. Windows include_path
include_path=".;c:\www\php
The default value for this directive is . (only the current directory).
To see that the setting is try ...
<?php phpinfo(); ?>
as info.php
This will show you all your system's settings for PHP.
ASKER
I have tried using your info.php and the following is for
include_path
.:/php/includes:/usr/share /php
What should I use then
include_path
.:/php/includes:/usr/share
What should I use then
That says that you can use the current directory
./
and 2 other directories
/php/includes
and
/usr/share/php
So. You can use ./Pager.php
Try this.
Create a new file in the same directory as Pager.php
<?php echo "I'm here!"; ?>
and call this test.php
Try calling test.php directly from your browser. Then replace the require statement you already have with
require "./test.php";
and then reload your script.
You should get the message at the top and a load of errors relating to the missing class.
Oh! Check the case too. I'm sure that is important on *IX systems.
Regards,
Richard.
./
and 2 other directories
/php/includes
and
/usr/share/php
So. You can use ./Pager.php
Try this.
Create a new file in the same directory as Pager.php
<?php echo "I'm here!"; ?>
and call this test.php
Try calling test.php directly from your browser. Then replace the require statement you already have with
require "./test.php";
and then reload your script.
You should get the message at the top and a load of errors relating to the missing class.
Oh! Check the case too. I'm sure that is important on *IX systems.
Regards,
Richard.
ASKER
When I used the test.php it worked out fine and printed
I'm Here but when I replaced with Pager.php
the following error is generated:
Fatal error: Cannot instantiate non-existent class: pager in /var/www/html/PageTest.php on line 9
isn't there something I should have installed?
I'm Here but when I replaced with Pager.php
the following error is generated:
Fatal error: Cannot instantiate non-existent class: pager in /var/www/html/PageTest.php
isn't there something I should have installed?
I can't believe this, but ...
class DB_Pager extends PEAR
is in Pager.php.
And the example code on the main site is wrong!!!!
Try ...
$pager = new DB_Pager ($result, $from, $limit);
class DB_Pager extends PEAR
is in Pager.php.
And the example code on the main site is wrong!!!!
Try ...
$pager = new DB_Pager ($result, $from, $limit);
ASKER
The error is now being generated in Pager.php.
Fatal error: Call to a member function on a non-object in /var/www/html/Pager.php on line 98
Fatal error: Call to a member function on a non-object in /var/www/html/Pager.php on line 98
ASKER
The error is now being generated in Pager.php.
Fatal error: Call to a member function on a non-object in /var/www/html/Pager.php on line 98
Don't I need
PEAR.php
and DB.php
Fatal error: Call to a member function on a non-object in /var/www/html/Pager.php on line 98
Don't I need
PEAR.php
and DB.php
Of course. You are using a PEAR_DB pager!
These are normally part of a PHP installation. If not, then you will need to get them.
I use a Windows environment and they come with PHP. If you are using a *IX environment, I'm not sure how to get it, but it involves CVS (I think).
I use a Windows environment and they come with PHP. If you are using a *IX environment, I'm not sure how to get it, but it involves CVS (I think).
ASKER
thanks
will try it out
will try it out
ASKER
I have the two files
in /usr/share/php folder but can't figure out why it's not working!
in /usr/share/php folder but can't figure out why it's not working!
ASKER
The following is the part code from Pager.php. I have labelled the line generating errors Lin 98.
class DB_Pager extends PEAR
{
/**
* Constructor
*
* @param object $res A DB_result object from Pear_DB
* @param int $from The row to start fetching
* @param int $limit How many results per page
* @param int $numrows Pager will automatically
* find this param if is not given. If your Pear_DB backend extension
* doesn't support numrows(), you can manually calculate it
* and supply later to the constructor
* @deprecated
*/
function DB_Pager (&$res, $from, $limit, $numrows = null)
{
$this->res = $res;
$this->from = $from;
$this->limit = $limit;
$this->numrows = $numrows;
}
/**
* Calculates all the data needed by Pager to work
*
* @return mixed An assoc array with all the data (see getData)
* or DB_Error on error
* @see DB_Pager::getData
* @deprecated
*/
function build()
{
// if there is no numrows given, calculate it
if ($this->numrows === null) {
$this->numrows = $this->res->numrows();**Li n 98
if (DB::isError($this->numrow s)) {
return $this->numrows;
}
}
$data = $this->getData($this->from , $this->limit, $this->numrows);
if (DB::isError($data)) {
return $data;
}
$this->current = $this->from - 1;
$this->top = $data['to'];
return $data;
}
class DB_Pager extends PEAR
{
/**
* Constructor
*
* @param object $res A DB_result object from Pear_DB
* @param int $from The row to start fetching
* @param int $limit How many results per page
* @param int $numrows Pager will automatically
* find this param if is not given. If your Pear_DB backend extension
* doesn't support numrows(), you can manually calculate it
* and supply later to the constructor
* @deprecated
*/
function DB_Pager (&$res, $from, $limit, $numrows = null)
{
$this->res = $res;
$this->from = $from;
$this->limit = $limit;
$this->numrows = $numrows;
}
/**
* Calculates all the data needed by Pager to work
*
* @return mixed An assoc array with all the data (see getData)
* or DB_Error on error
* @see DB_Pager::getData
* @deprecated
*/
function build()
{
// if there is no numrows given, calculate it
if ($this->numrows === null) {
$this->numrows = $this->res->numrows();**Li
if (DB::isError($this->numrow
return $this->numrows;
}
}
$data = $this->getData($this->from
if (DB::isError($data)) {
return $data;
}
$this->current = $this->from - 1;
$this->top = $data['to'];
return $data;
}
You should be able to comment out the Build function as it is no longer in use (according to the notes in the file).
Split.
With 35 points we cannot make split.
Ha. Only I commented anyway. So me then!
ASKER
DB Pager-0[1].7.tar but how to start using it and the version of php it supports is a problem.
I am new to php