?
Solved

PearDB

Posted on 2002-07-16
22
Medium Priority
?
336 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 9
22 Comments
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 140 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

777 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