Solved

PearDB

Posted on 2002-07-16
22
329 Views
Last Modified: 2007-12-19
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.
0
Comment
Question by:mafiq
  • 9
  • 9
22 Comments
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 35 total points
ID: 7159122
Are you using ...

http://vulcanonet.com/soft/index.php?pack=pager


If so, then download the code from the page and use it!

If you are getting errors, what are they?
0
 

Author Comment

by:mafiq
ID: 7161340
Yes, I have already downloaded the file named

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
0
 

Author Comment

by:mafiq
ID: 7162103
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."'"."?from='".$data['next']."'".">'".$data['remain']."'"."Next->"."</a>";
  foreach ($data['pages'] as $page => $start_row)
  {
    echo "<a href='$PHP_SELF?from=$start_row'>$page</a>";
   }
   while ($row = $pager->fetchRow(DB_FETCHMODE_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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7168904
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\phplib"
 
 
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.
0
 

Author Comment

by:mafiq
ID: 7171102
I have tried using your info.php and the following is for

include_path

.:/php/includes:/usr/share/php

What should I use then



0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7171393
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.
0
 

Author Comment

by:mafiq
ID: 7171420
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?


0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7171436
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);

0
 

Author Comment

by:mafiq
ID: 7171468
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
0
 

Author Comment

by:mafiq
ID: 7171472
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
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7171473
Of course. You are using a PEAR_DB pager!
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7171476
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).
0
 

Author Comment

by:mafiq
ID: 7171482
thanks

will try it out
0
 

Author Comment

by:mafiq
ID: 7171628
I have the two files

in /usr/share/php folder but can't figure out why it's not working!
0
 

Author Comment

by:mafiq
ID: 7171695
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();**Lin 98
            if (DB::isError($this->numrows)) {
                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;
    }
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7171728
You should be able to comment out the Build function as it is no longer in use (according to the notes in the file).
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 11665063
Split.
0
 
LVL 20

Expert Comment

by:Venabili
ID: 11665104
With 35 points we cannot make split.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 11665205
Ha. Only I commented anyway. So me then!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question