www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: Query a db with Pear

  1. #1
    Join Date
    Jul 2009
    Location
    UK
    Posts
    174

    Query a db with Pear

    hi

    I'm trying to run a script that makes use of Pear. You may see the code from the screen shot attached. I have a problem with my Pear configuration. When I run the script via Apache I get: Fatal error: Class 'DB' not found in C:\Program Files[. Are there any Pear experts out there?? Ive had a look at the http://pear.php.net/ manual but am finding it inpenetrable.
    Attached Images Attached Images
    • File Type: jpg x.jpg (91.6 KB, 63 views)

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    Assuming that the correct DB.php file is loaded by your require statement, that error message does not make much sense. You might want to try requiring it via its full path name in case another file in the include_path is being loaded instead.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jul 2009
    Location
    UK
    Posts
    174
    Quote Originally Posted by NogDog View Post
    Assuming that the correct DB.php file is loaded by your require statement, that error message does not make much sense. You might want to try requiring it via its full path name in case another file in the include_path is being loaded instead.
    hi NogDog

    The DB.php is in the same directory as the script?. My php.ini includes path is attached in a screenshot; is this ok?.
    Attached Images Attached Images
    • File Type: jpg y.jpg (13.3 KB, 38 views)

  4. #4
    Join Date
    Jul 2009
    Location
    UK
    Posts
    174
    If I replace the variables with the appropriate constansts, then I still get the same error!

    i.e.

    $host="localhost";
    $user="root";
    $passwd="*****";
    $database="library";

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    The error is telling you that no class named "DB" has been defined when you try to use it. Presumably it should have been defined by that require statement, so at this point I really don't know why that should be based on the evidence provided so far.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  6. #6
    Join Date
    Jul 2009
    Location
    UK
    Posts
    174
    Quote Originally Posted by NogDog View Post
    The error is telling you that no class named "DB" has been defined when you try to use it. Presumably it should have been defined by that require statement, so at this point I really don't know why that should be based on the evidence provided so far.
    looks like that's my 'Pear' experience cut short then..

  7. #7
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    Probably there's some "silly" error here that I'm just not seeing in the supplied code. You might want to try something really basic to see if anything obvious jumps out:
    PHP Code:
    <?php
    <?php
    ini_set
    ('dipslay_errors'1);
    error_reporting(E_ALL);
    require_once 
    'DB.php';
    $db = new DB();
    echo 
    "<pre>".print_r($db1)."</pre>";
    It should display something like the following if it works:
    Code:
    DB Object
    (
    )
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  8. #8
    Join Date
    Jul 2009
    Location
    UK
    Posts
    174
    Quote Originally Posted by NogDog View Post
    Probably there's some "silly" error here that I'm just not seeing in the supplied code. You might want to try something really basic to see if anything obvious jumps out:
    PHP Code:
    <?php
    <?php
    ini_set
    ('dipslay_errors'1);
    error_reporting(E_ALL);
    require_once 
    'DB.php';
    $db = new DB();
    echo 
    "<pre>".print_r($db1)."</pre>";
    It should display something like the following if it works:
    Code:
    DB Object
    (
    )
    ...hmm, that's interesting, upon testing this code my browser displays:

    Fatal error: Class 'DB' not found in C:\Program Files

  9. #9
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    Try changing the require statement to the following, just in case it's an include_path issue:
    PHP Code:
    require_once "./DB.php"
    (This assumes that as you mentioned above, the desired DB.php file is in the same directory as your test script.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  10. #10
    Join Date
    Jul 2009
    Location
    UK
    Posts
    174
    Quote Originally Posted by NogDog View Post
    Try changing the require statement to the following, just in case it's an include_path issue:
    PHP Code:
    require_once "./DB.php"
    (This assumes that as you mentioned above, the desired DB.php file is in the same directory as your test script.)
    Well, I think we can deduce it's not an include path issue. I run the script with the changes and get the exact same error.

  11. #11
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    Only other thing I can think of is that there's something wrong with the DB.php file itself. I did a local install of the PEAR DB package on my PC and the same test script runs fine.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  12. #12
    Join Date
    Jul 2009
    Location
    UK
    Posts
    174
    Quote Originally Posted by NogDog View Post
    Only other thing I can think of is that there's something wrong with the DB.php file itself. I did a local install of the PEAR DB package on my PC and the same test script runs fine.
    ...oh, the DB.php file is:

    PHP Code:
    <?php
    $host
    ="localhost";
    $user="root";
    $passwd="password";
    $database="library";
    ?>
    which is in the same directory..

    I think i'm going to have to look at the DB installation further. Hey, thanks for all your help NogDog, I appreciate your'e help.
    Last edited by 1cookie; 11-15-2009 at 12:49 PM.

  13. #13
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    That is definitely not the PEAR DB script. The version I have is about 1490 lines long.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  14. #14
    Join Date
    Jul 2009
    Location
    UK
    Posts
    174
    I run the go-pear.bat batch file, see screen shot please. Can you deduce anything from this??
    Attached Images Attached Images
    • File Type: jpg k.jpg (91.2 KB, 33 views)

  15. #15
    Join Date
    Jul 2009
    Location
    UK
    Posts
    174
    Quote Originally Posted by NogDog View Post
    That is definitely not the PEAR DB script. The version I have is about 1490 lines long.
    ah, turns out I have a misunderstanding with just exactly what DB.php consists of.. I'm reading from a book, and it's like, hopeless...

    Question, DB.php DOES come bundled with my php installation?
    Last edited by 1cookie; 11-15-2009 at 01:33 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles