• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

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.
0
mafiq
Asked:
mafiq
  • 9
  • 9
1 Solution
 
Richard QuadlingSenior Software DeveloperCommented:
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
 
mafiqAuthor Commented:
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
 
mafiqAuthor Commented:
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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
Richard QuadlingSenior Software DeveloperCommented:
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
 
mafiqAuthor Commented:
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
 
Richard QuadlingSenior Software DeveloperCommented:
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
 
mafiqAuthor Commented:
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
 
Richard QuadlingSenior Software DeveloperCommented:
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
 
mafiqAuthor Commented:
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
 
mafiqAuthor Commented:
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
 
Richard QuadlingSenior Software DeveloperCommented:
Of course. You are using a PEAR_DB pager!
0
 
Richard QuadlingSenior Software DeveloperCommented:
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
 
mafiqAuthor Commented:
thanks

will try it out
0
 
mafiqAuthor Commented:
I have the two files

in /usr/share/php folder but can't figure out why it's not working!
0
 
mafiqAuthor Commented:
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
 
Richard QuadlingSenior Software DeveloperCommented:
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
 
Richard QuadlingSenior Software DeveloperCommented:
Split.
0
 
VenabiliCommented:
With 35 points we cannot make split.
0
 
Richard QuadlingSenior Software DeveloperCommented:
Ha. Only I commented anyway. So me then!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 9
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now